diff --git a/@stellar/typescript-wallet-sdk/package.json b/@stellar/typescript-wallet-sdk/package.json index db16e7d..154bd6b 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", 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..769e82e --- /dev/null +++ b/@stellar/typescript-wallet-sdk/test/e2e/browser.test.ts @@ -0,0 +1,43 @@ +import { chromium } from "playwright"; + +describe("Test browser build", () => { + it("works", async () => { + await (async () => { + const browser = await chromium.launch(); + const page = await browser.newPage(); + + await page.goto("https://stellar.org"); + + await page.addScriptTag({ + path: "@stellar/typescript-wallet-sdk/lib/bundle_browser.js", + }); + + // Use the Stellar SDK in the website's context + const result = await page.evaluate(() => { + let kp; + try { + console.log(window.WalletSDK); + + const wal = window.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/@stellar/typescript-wallet-sdk/webpack.config.js b/@stellar/typescript-wallet-sdk/webpack.config.js index 4d24803..1067ba9 100644 --- a/@stellar/typescript-wallet-sdk/webpack.config.js +++ b/@stellar/typescript-wallet-sdk/webpack.config.js @@ -2,8 +2,6 @@ const path = require("path"); const webpack = require("webpack"); module.exports = (env = { NODE: false }) => { - console.log("webpack env:", { env }); // ALEC TODO - remove - const isBrowser = !env.NODE; return { 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"