-
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.
Merge pull request #36 from ChainSafe/willem/integration-testing-fram…
…ework Add e2e testing framework for WebZjs
- Loading branch information
Showing
12 changed files
with
451 additions
and
125 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,39 @@ | ||
name: Playwright Tests | ||
on: | ||
pull_request: | ||
push: | ||
branches: main | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Just | ||
uses: extractions/setup-just@v2 | ||
|
||
- name: install wasm-pack | ||
uses: jetli/[email protected] | ||
with: | ||
version: latest | ||
|
||
- name: build pkg | ||
run: just build | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
|
||
- uses: pnpm/action-setup@v4 | ||
|
||
- name: Install dependencies | ||
run: pnpm i | ||
|
||
- name: Install Playwright Browsers | ||
working-directory: ./packages/e2e-tests/ | ||
run: npx playwright install --with-deps | ||
|
||
- name: Run Playwright tests | ||
run: pnpm run test:e2e |
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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ | ||
!dist/serve.json |
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,23 @@ | ||
# WebZ e2e Tests | ||
|
||
This package uses playwright to test the highest level API of WebZjs running in a browser. This allows testing the interaction of different WebWorkers with the page, as well as testing on different browsers. | ||
|
||
## Writing Tests | ||
|
||
New tests should be added as files named `.spec.ts` inside the `e2e` directory. | ||
|
||
Tests should use the `page.evaluate` method from playwright to execute javascript code in the browser page where the wallet exists and return a result to the test runner to check. e.g. | ||
|
||
```typescript | ||
test('Test some webz functionality..', async ({ page }) => { | ||
// code here runs in the test runner (node), not in the browser | ||
let result = await page.evaluate(async () => { | ||
// everything here executes in the web page | ||
// - do something with window.webWallet.. | ||
return // the result to the test runner | ||
}); | ||
expect(result).toBe(something); | ||
}); | ||
``` | ||
|
||
The provided page has already initialized the Wasm environment and created a web wallet accessible in tests as `window.webWallet` |
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,18 @@ | ||
{ | ||
"headers": [ | ||
{ | ||
"source": "**/*", | ||
"headers": [ | ||
{ | ||
"key": "Cross-Origin-Opener-Policy", | ||
"value": "same-origin" | ||
}, | ||
{ | ||
"key": "Cross-Origin-Embedder-Policy", | ||
"value": "require-corp" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
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,25 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { WebWallet } from "@webzjs/webz-core"; | ||
|
||
declare global { | ||
interface Window { webWallet: WebWallet; } | ||
} | ||
|
||
const SEED = "mix sample clay sweet planet lava giraffe hand fashion switch away pool rookie earth purity truly square trumpet goose move actor save jaguar volume"; | ||
const BIRTHDAY = 2657762; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("http://127.0.0.1:8081"); | ||
await page.waitForFunction(() => window.webWallet !== undefined); | ||
await page.evaluate(async ({seed, birthday}) => { | ||
await window.webWallet.create_account(seed, 0, birthday); | ||
}, { seed: SEED, birthday: BIRTHDAY }); | ||
}); | ||
|
||
test('Account was added', async ({ page }) => { | ||
let result = await page.evaluate(async () => { | ||
let summary = await window.webWallet.get_wallet_summary(); | ||
return summary?.account_balances.length; | ||
}); | ||
expect(result).toBe(1); | ||
}); |
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,19 @@ | ||
{ | ||
"name": "e2e-tests", | ||
"version": "1.0.0", | ||
"description": "", | ||
"source": "src/index.html", | ||
"scripts": { | ||
"pretest": "parcel build", | ||
"test": "playwright test" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.47.2", | ||
"@types/node": "^22.7.4", | ||
"@webzjs/webz-core": "workspace:^", | ||
"serve": "^14.2.3" | ||
} | ||
} |
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,79 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// import path from 'path'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './e2e', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'serve -l 8081 ./dist -c ./serve.json', | ||
url: 'http://127.0.0.1:8081', | ||
// reuseExistingServer: !process.env.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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>WebZjs e2e testing</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="index.js"></script> | ||
</body> | ||
</html> |
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,23 @@ | ||
import initWasm, { initThreadPool, WebWallet } from "@webzjs/webz-core"; | ||
|
||
const N_THREADS = 10; | ||
const MAINNET_LIGHTWALLETD_PROXY = "https://zcash-mainnet.chainsafe.dev"; | ||
|
||
async function loadPage() { | ||
await new Promise((resolve) => { | ||
window.addEventListener("load", resolve); | ||
}); | ||
|
||
// Code to executed once the page has loaded | ||
await initWasm(); | ||
await initThreadPool(N_THREADS); | ||
window.webWallet = new WebWallet( | ||
"main", | ||
MAINNET_LIGHTWALLETD_PROXY, | ||
1 | ||
); | ||
console.log("WebWallet initialized"); | ||
console.log(webWallet); | ||
} | ||
|
||
loadPage(); |
Oops, something went wrong.