Skip to content

Commit

Permalink
[wip] dappwright
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Nov 2, 2024
1 parent 88143e1 commit c5fc49f
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 32 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci-playwright.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: playwright-test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
playwright-test:
runs-on: ubuntu-latest
services:
sapphire-localnet-ci:
image: ghcr.io/oasisprotocol/sapphire-localnet:latest
ports:
- 8545:8545
- 8546:8546
env:
OASIS_DEPOSIT_BINARY: /oasis-deposit -test-mnemonic -n 5
options: >-
--rm
--health-cmd="test -f /CONTAINER_READY"
--health-start-period=90s
env:
SAPPHIRE_LOCALNET_HTTP_PROXY_PORT: 3001
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install jq
run: sudo apt install -y jq
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Build JS client
run: make -C clients/js build
- name: Build Integrations
run: make -C integrations build ## TODO build only
- uses: JarvusInnovations/background-action@v1
name: RPC proxy will error if non-encrypted calls are made
with:
run: pnpm run proxy &
wait-on: http://127.0.0.1:${{ env.SAPPHIRE_LOCALNET_HTTP_PROXY_PORT }}
tail: true
log-output-resume: true
wait-for: 31sec
log-output: true
log-output-if: true
working-directory: clients/js
- name: Checkout code
uses: actions/checkout@v4
# - name: Start example
# run: pnpm dev &
# working-directory: examples/wagmi-v2
# - name: Wait on Application
# run: npx wait-on http://localhost:5173/ --timeout 60000
- name: Set up playwright tests
run: pnpm playwright install
- name: Run playwright tests
working-directory: examples/wagmi-v2
run: pnpm test
- name: 'Upload playwright test-results'
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: playwright-test-results
path: playwright/test-results
retention-days: 5
5 changes: 4 additions & 1 deletion examples/wagmi-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
"lint": "biome check .",
"format": "biome format --write .",
"preview": "vite preview",
"test": "playwright test test/e2e.spec.ts",
"start:server": "vite --port 3000"
},
"dependencies": {
"@oasisprotocol/sapphire-wagmi-v2": "workspace:^",
"@oasisprotocol/sapphire-paratime": "workspace:^",
"@oasisprotocol/sapphire-wagmi-v2": "workspace:^",
"@playwright/test": "^1.48.2",
"@tanstack/react-query": "5.0.5",
"@tenkeylabs/dappwright": "^2.8.6",
"abitype": "^1.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
46 changes: 46 additions & 0 deletions examples/wagmi-v2/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { defineConfig, devices } from "@playwright/test";

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
timeout: 2 * 60 * 1000,
testDir: "./test/e2e/",
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"], ["list", { printSteps: true }]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: process.env.FRONTEND_URL || "http://localhost:3000/",
trace: "on-first-retry",
headless: false,
screenshot: {
mode: "only-on-failure",
fullPage: true,
},
},
/* Configure projects for major browsers */
projects: [
{
name: 'main',
testDir: './test/',
use: {
...devices['Desktop Chrome'],
},
},
],
/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm run start:server',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
// stdout: 'ignore',
stderr: 'pipe',
},
});
50 changes: 50 additions & 0 deletions examples/wagmi-v2/test/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { BrowserContext, expect, test as baseTest } from "@playwright/test";
import dappwright, { Dappwright, MetaMaskWallet } from "@tenkeylabs/dappwright";

export const test = baseTest.extend<{
context: BrowserContext;
wallet: Dappwright;
}>({
context: async ({}, use) => {
// Launch context with extension
const [wallet, _, context] = await dappwright.bootstrap("", {
wallet: "metamask",
version: MetaMaskWallet.recommendedVersion,
seed: "test test test test test test test test test test test junk", // Hardhat's default https://hardhat.org/hardhat-network/docs/reference#accounts
headless: false,
});

// Add Hardhat as a custom network
await wallet.addNetwork({
networkName: "Sapphire Localnet",
rpc: "http://localhost:8545",
chainId: 23293,
symbol: "ROSE",
});

await use(context);
},

wallet: async ({ context }, use) => {
const metamask = await dappwright.getWallet("metamask", context);

await use(metamask);
},
});

test.beforeEach(async ({ page }) => {
await page.goto("http://localhost:3000");
});

test("should be able to connect", async ({ wallet, page }) => {
await page.click("#connect-button");
await wallet.approve();

const connectStatus = page.getByTestId("connect-status");
expect(connectStatus).toHaveValue("connected");

await page.click("#switch-network-button");

const networkStatus = page.getByTestId("network-status");
expect(networkStatus).toHaveValue("23293");
});
Loading

0 comments on commit c5fc49f

Please sign in to comment.