-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pilot-app): e2e for companion app (#571)
* start migrating existing e2e tests to companion app * globally ignore playwright output * make some adjustments to tests * run app e2e tests * adjust commands * change default working directory * add type import * hacky way to get the deployment url * use correct output field * use explicit string * reduce test flakiness * fix yaml.. maybe... * maybe fix regex * try newer action * simplify regex * use match * remove console log * fix wrong assertion
- Loading branch information
1 parent
0841ce1
commit 6b941e7
Showing
23 changed files
with
469 additions
and
15 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Pilot App | ||
name: Companion App | ||
|
||
on: | ||
pull_request: | ||
|
@@ -10,7 +10,10 @@ defaults: | |
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
name: Deploy | ||
name: Deploy & Test | ||
defaults: | ||
run: | ||
working-directory: ./deployables/app | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
|
@@ -19,12 +22,41 @@ jobs: | |
node-version: latest | ||
cache: 'pnpm' | ||
cache-dependency-path: '**/pnpm-lock.yaml' | ||
|
||
- run: pnpm install --prefer-offline | ||
|
||
- run: pnpm build | ||
|
||
- name: Deploy | ||
id: deploy | ||
uses: cloudflare/[email protected] | ||
with: | ||
workingDirectory: deployables/app | ||
apiToken: ${{ secrets.CF_API_TOKEN }} | ||
accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
command: versions upload | ||
|
||
# If you think this sucks, you are right. | ||
# Check https://github.com/cloudflare/wrangler-action/issues/343 | ||
# and we can just use the deployment-url output of | ||
# the deploy action | ||
- uses: kaisugi/[email protected] | ||
id: regex | ||
with: | ||
text: ${{ steps.deploy.outputs.command-output }} | ||
regex: 'https:\/\/.+\.gnosisguild\.workers\.dev' | ||
|
||
- name: Install Playwright Browsers | ||
run: pnpm playwright install --with-deps chromium | ||
|
||
- name: Run Playwright tests | ||
run: xvfb-run pnpm playwright test | ||
env: | ||
PLAYWRIGHT_TEST_BASE_URL: ${{ steps.regex.outputs.match }} | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -7,4 +7,8 @@ coverage | |
.turbo | ||
|
||
.env | ||
*.log | ||
*.log | ||
|
||
playwright/.cache/ | ||
playwright-report/ | ||
test-results/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import test, { expect } from '@playwright/test' | ||
import { mockWeb3 } from '@zodiac/test-utils/e2e' | ||
import { connectWallet } from '../connectWallet' | ||
|
||
test.describe('Locked account', () => { | ||
const account = '0x1000000000000000000000000000000000000000' | ||
|
||
test('handles wallet disconnect gracefully', async ({ page }) => { | ||
const { lockWallet } = await mockWeb3(page) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page) | ||
await lockWallet() | ||
|
||
await expect( | ||
page.getByRole('alert', { name: 'Wallet disconnected' }), | ||
).toBeInViewport() | ||
}) | ||
|
||
test('it is possible to reconnect an account', async ({ page }) => { | ||
const { lockWallet } = await mockWeb3(page, { | ||
accounts: [account], | ||
}) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page, account) | ||
await lockWallet() | ||
|
||
await page.getByRole('button', { name: 'Connect', exact: true }).click() | ||
|
||
await expect( | ||
page.getByRole('textbox', { name: 'Pilot Account' }), | ||
).toHaveValue(account) | ||
}) | ||
|
||
test('it is possible to disconnect a locked account', async ({ page }) => { | ||
const { lockWallet } = await mockWeb3(page) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page) | ||
await lockWallet() | ||
|
||
await page.getByRole('button', { name: 'Disconnect' }).click() | ||
|
||
await expect( | ||
page.getByRole('button', { name: 'Connect wallet' }), | ||
).toBeInViewport() | ||
}) | ||
}) |
24 changes: 24 additions & 0 deletions
24
deployables/app/e2e/accountHandling/unavailableWallet.spec.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,24 @@ | ||
import test, { expect } from '@playwright/test' | ||
import { mockWeb3 } from '@zodiac/test-utils/e2e' | ||
import { connectWallet } from '../connectWallet' | ||
|
||
test.describe('Account unavailable', () => { | ||
test('handles unavailable accounts gracefully', async ({ page }) => { | ||
const { loadAccounts } = await mockWeb3(page, { | ||
accounts: ['0x1000000000000000000000000000000000000000'], | ||
}) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page, '0x1000000000000000000000000000000000000000') | ||
await loadAccounts(['0x2000000000000000000000000000000000000000']) | ||
|
||
await expect( | ||
page.getByRole('alert', { | ||
name: `Account is not connected`, | ||
}), | ||
).toHaveAccessibleDescription( | ||
'Switch your wallet to this account in order to use Pilot.', | ||
) | ||
}) | ||
}) |
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,33 @@ | ||
import test, { expect } from '@playwright/test' | ||
import { mockWeb3 } from '@zodiac/test-utils/e2e' | ||
import { connectWallet } from '../connectWallet' | ||
|
||
test.describe('Wrong chain selected', () => { | ||
test('it is possible to switch to the correct chain', async ({ page }) => { | ||
const { switchChain } = await mockWeb3(page) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page) | ||
await switchChain(10) | ||
|
||
await expect( | ||
page.getByRole('alert', { name: 'Chain mismatch' }), | ||
).toBeInViewport() | ||
}) | ||
|
||
test('it is possible to switch back to the connected chain', async ({ | ||
page, | ||
}) => { | ||
const { switchChain } = await mockWeb3(page) | ||
|
||
await page.goto('/new-route') | ||
|
||
await connectWallet(page) | ||
await switchChain(10) | ||
|
||
await expect( | ||
page.getByRole('button', { name: 'Switch wallet to Ethereum' }), | ||
).toBeInViewport() | ||
}) | ||
}) |
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,13 @@ | ||
import { expect, type Page } from '@playwright/test' | ||
import { defaultMockAccount } from '@zodiac/test-utils/e2e' | ||
|
||
export const connectWallet = async ( | ||
page: Page, | ||
account: `0x${string}` = defaultMockAccount, | ||
) => { | ||
await page.getByRole('button', { name: 'Connect wallet' }).click() | ||
await page.getByRole('button', { name: 'Browser Wallet' }).click() | ||
await expect( | ||
page.getByRole('textbox', { name: 'Pilot Account' }), | ||
).toHaveValue(account) | ||
} |
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 @@ | ||
import test, { expect } from '@playwright/test' | ||
|
||
test('connection to example app', async ({ page }) => { | ||
await page.goto('/new-route') | ||
|
||
await expect( | ||
page.getByRole('heading', { name: 'Route configuration' }), | ||
).toBeInViewport() | ||
}) |
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 @@ | ||
/* eslint-disable no-empty-pattern, react-hooks/rules-of-hooks */ | ||
import { test as base, chromium, type BrowserContext } from '@playwright/test' | ||
import { fileURLToPath } from 'url' | ||
|
||
export const test = base.extend<{ | ||
context: BrowserContext | ||
extensionId: string | ||
}>({ | ||
context: async ({}, use) => { | ||
const pathToExtension = fileURLToPath( | ||
new URL('../../public', import.meta.url), | ||
) | ||
|
||
const context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
args: [ | ||
`--disable-extensions-except=${pathToExtension}`, | ||
`--load-extension=${pathToExtension}`, | ||
], | ||
ignoreDefaultArgs: [ | ||
'--disable-component-extensions-with-background-pages', | ||
], | ||
}) | ||
|
||
await use(context) | ||
await context.close() | ||
}, | ||
|
||
extensionId: async ({ context }, use) => { | ||
let [background] = context.serviceWorkers() | ||
if (!background) background = await context.waitForEvent('serviceworker') | ||
|
||
const extensionId = background.url().split('/')[2] | ||
|
||
await use(extensionId) | ||
}, | ||
}) | ||
|
||
export const expect = test.expect |
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 @@ | ||
import type { Page } from '@playwright/test' | ||
import { waitFor } from '@zodiac/test-utils/e2e' | ||
|
||
export const getExtensionPage = (page: Page) => | ||
waitFor(() => { | ||
const extension = page | ||
.context() | ||
.pages() | ||
.find((page) => page.url().startsWith('chrome-extension')) | ||
|
||
if (extension == null) { | ||
throw new Error('Extension not found') | ||
} | ||
|
||
return extension | ||
}) |
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,4 @@ | ||
export { expect, test } from './fixture' | ||
export { loadExtension } from './loadExtension' | ||
export { defaultMockAccount, mockWeb3 } from './mockWeb3' | ||
export { waitFor } from './waitFor' |
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,10 @@ | ||
import type { Page } from '@playwright/test' | ||
import { getExtensionPage } from './getExtensionPage' | ||
|
||
export const loadExtension = async (page: Page) => { | ||
await page.goto('/') | ||
|
||
await page.getByRole('button', { name: 'Open extension' }).click() | ||
|
||
return getExtensionPage(page) | ||
} |
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,44 @@ | ||
import { defineConfig, devices } from '@playwright/test' | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
|
||
/** | ||
* 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: process.env.CI ? 'github' : '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: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3040', | ||
|
||
/* 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'] }, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}) |
Oops, something went wrong.