Skip to content

Commit

Permalink
Add e2e test for testing browser build (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
acharb authored Apr 22, 2024
1 parent 7363757 commit 0609ced
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/playwrightTests.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions @stellar/typescript-wallet-sdk/jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rootDir: "./",
preset: "ts-jest",
transform: {
"^.+\\.(ts|tsx)?$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
testMatch: ["**/e2e/*.test.ts"],
};
2 changes: 2 additions & 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 Expand Up @@ -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",
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
52 changes: 52 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,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,
);
}
});
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
{
displayName: "Wallet SDK",
roots: ["./@stellar/typescript-wallet-sdk"],
testPathIgnorePatterns: ["/node_modules/", "/integration/"],
testPathIgnorePatterns: ["/node_modules/", "/integration/", "/e2e/"],
...commonConfigs,
},
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 0609ced

Please sign in to comment.