-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test for testing browser build (#126)
- Loading branch information
Showing
8 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters