Skip to content

Commit

Permalink
test browser build
Browse files Browse the repository at this point in the history
  • Loading branch information
acharb committed Apr 22, 2024
1 parent 18f0382 commit 2bb8554
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions @stellar/typescript-wallet-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions @stellar/typescript-wallet-sdk/test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions @stellar/typescript-wallet-sdk/test/e2e/browser.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 0 additions & 2 deletions @stellar/typescript-wallet-sdk/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2bb8554

Please sign in to comment.