diff --git a/.github/workflows/playwrightTests.yml b/.github/workflows/playwrightTests.yml new file mode 100644 index 0000000..97898b9 --- /dev/null +++ b/.github/workflows/playwrightTests.yml @@ -0,0 +1,16 @@ +name: Playwright Tests +on: [pull_request] +jobs: + playwright: + name: "Playwright e2e Tests" + runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.43.0-jammy + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: 18 + - run: yarn install + - run: yarn build + - run: yarn test:e2e:ci diff --git a/@stellar/typescript-wallet-sdk/jest.e2e.config.js b/@stellar/typescript-wallet-sdk/jest.e2e.config.js new file mode 100644 index 0000000..ea8b056 --- /dev/null +++ b/@stellar/typescript-wallet-sdk/jest.e2e.config.js @@ -0,0 +1,9 @@ +module.exports = { + rootDir: "./", + preset: "ts-jest", + transform: { + "^.+\\.(ts|tsx)?$": "ts-jest", + "^.+\\.(js|jsx)$": "babel-jest", + }, + testMatch: ["**/e2e/*.test.ts"], +}; diff --git a/@stellar/typescript-wallet-sdk/package.json b/@stellar/typescript-wallet-sdk/package.json index db16e7d..d9b7a36 100644 --- a/@stellar/typescript-wallet-sdk/package.json +++ b/@stellar/typescript-wallet-sdk/package.json @@ -29,6 +29,7 @@ "jest": "^29.4.1", "lint-staged": "^14.0.1", "npm-run-all": "^4.1.5", + "playwright": "^1.43.1", "prettier": "^2.0.5", "pretty-quick": "^2.0.1", "process": "^0.11.10", @@ -61,6 +62,7 @@ "scripts": { "test": "jest --watchAll", "test:ci": "jest --ci", + "test:e2e:ci": "jest --config jest.e2e.config.js --ci", "test:recovery:ci": "jest --config jest.integration.config.js recovery.test.ts --ci", "test:anchorplatform:ci": "yarn jest --config jest.integration.config.js anchorplatform.test.ts --ci", "build:web": "webpack --config webpack.config.js", diff --git a/@stellar/typescript-wallet-sdk/test/e2e/README.md b/@stellar/typescript-wallet-sdk/test/e2e/README.md new file mode 100644 index 0000000..19776e8 --- /dev/null +++ b/@stellar/typescript-wallet-sdk/test/e2e/README.md @@ -0,0 +1,11 @@ +# How it works + +## browser.test.ts + +This test uses playwright to load the browser bundle file into a browser +environment and run its code. If there is a bug in how its built, +window.WalletSDK will be undefined. + +### To run + +$ yarn build $ yarn test browser.test.ts diff --git a/@stellar/typescript-wallet-sdk/test/e2e/browser.test.ts b/@stellar/typescript-wallet-sdk/test/e2e/browser.test.ts new file mode 100644 index 0000000..62fa754 --- /dev/null +++ b/@stellar/typescript-wallet-sdk/test/e2e/browser.test.ts @@ -0,0 +1,52 @@ +import { chromium, webkit } from "playwright"; + +describe("Test browser build", () => { + const browsers = [ + { name: "Chrome", instance: chromium }, + { name: "Safari", instance: webkit }, + ]; + + for (const b of browsers) { + it( + "works on " + b.name, + async () => { + await (async () => { + const browser = await b.instance.launch(); + const page = await browser.newPage(); + + await page.goto("https://stellar.org"); + + await page.addScriptTag({ + path: "./lib/bundle_browser.js", + }); + + // Use the Stellar SDK in the website's context + const result = await page.evaluate(() => { + let kp; + try { + const wal = (window as any).WalletSDK.Wallet.TestNet(); + const account = wal.stellar().account(); + + kp = account.createKeypair(); + } catch (e) { + return { success: false }; + } + + return { + publicKey: kp.publicKey, + secretKey: kp.secretKey, + success: true, + }; + }); + + expect(result.publicKey).toBeTruthy(); + expect(result.secretKey).toBeTruthy(); + expect(result.success).toBeTruthy(); + + await browser.close(); + })(); + }, + 15000, + ); + } +}); diff --git a/jest.config.js b/jest.config.js index 9d3582e..94b2794 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,7 +9,7 @@ module.exports = { { displayName: "Wallet SDK", roots: ["./@stellar/typescript-wallet-sdk"], - testPathIgnorePatterns: ["/node_modules/", "/integration/"], + testPathIgnorePatterns: ["/node_modules/", "/integration/", "/e2e/"], ...commonConfigs, }, { diff --git a/package.json b/package.json index b2834ba..12fef58 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "lint": "eslint . --ext .ts", "test": "jest --watchAll", "test:ci": "jest --ci", + "test:e2e:ci": "yarn workspace @stellar/typescript-wallet-sdk test:e2e:ci", "test:recovery:ci": "yarn workspace @stellar/typescript-wallet-sdk test:recovery:ci", "test:anchorplatform:ci": "yarn workspace @stellar/typescript-wallet-sdk test:anchorplatform:ci", "build": "yarn workspace @stellar/typescript-wallet-sdk build && yarn workspace @stellar/typescript-wallet-sdk-km build && yarn workspace @stellar/typescript-wallet-sdk-soroban build" diff --git a/yarn.lock b/yarn.lock index 65a5f19..3e6e65e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4527,7 +4527,7 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2: +fsevents@2.3.2, fsevents@^2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== @@ -6573,6 +6573,20 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +playwright-core@1.43.1: + version "1.43.1" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.43.1.tgz#0eafef9994c69c02a1a3825a4343e56c99c03b02" + integrity sha512-EI36Mto2Vrx6VF7rm708qSnesVQKbxEWvPrfA1IPY6HgczBplDx7ENtx+K2n4kJ41sLLkuGfmb0ZLSSXlDhqPg== + +playwright@^1.43.1: + version "1.43.1" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.43.1.tgz#8ad08984ac66c9ef3d0db035be54dd7ec9f1c7d9" + integrity sha512-V7SoH0ai2kNt1Md9E3Gwas5B9m8KR2GVvwZnAI6Pg0m3sh7UvgiYhRrhsziCmqMJNouPckiOhk8T+9bSAK0VIA== + dependencies: + playwright-core "1.43.1" + optionalDependencies: + fsevents "2.3.2" + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"