Skip to content

Commit

Permalink
add e2e testing framework that can run tests using an instance of webzjs
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Oct 1, 2024
1 parent 62dc517 commit e611b14
Show file tree
Hide file tree
Showing 10 changed files with 876 additions and 119 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"start:dev": "parcel --no-autoinstall packages/demo-wallet",
"build": "parcel build --no-cache --no-autoinstall packages/demo-wallet"
"build": "parcel build --no-cache --no-autoinstall packages/demo-wallet",
"test": "pnpm -r test"
},
"dependencies": {
"@webzjs/webz-core": "workspace:^",
Expand Down
110 changes: 0 additions & 110 deletions packages/demo-wallet/tsconfig.json

This file was deleted.

27 changes: 27 additions & 0 deletions packages/e2e-tests/.github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 6 additions & 0 deletions packages/e2e-tests/.gitignore
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
25 changes: 25 additions & 0 deletions packages/e2e-tests/e2e/e2e.spec.ts
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);
});
19 changes: 19 additions & 0 deletions packages/e2e-tests/package.json
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"
}
}
79 changes: 79 additions & 0 deletions packages/e2e-tests/playwright.config.ts
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,
},
});
11 changes: 11 additions & 0 deletions packages/e2e-tests/src/index.html
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>
23 changes: 23 additions & 0 deletions packages/e2e-tests/src/index.js
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();
Loading

0 comments on commit e611b14

Please sign in to comment.