Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/e2e pipeline #1238

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d4470a4
chore: skeleton e2e structure
JonathanConn Jul 17, 2023
1af8c2a
merge V2 into feat/e2e
JonathanConn Jul 18, 2023
0d6fb93
feat: explorer tests
JonathanConn Jul 18, 2023
be42dcc
feat: made wallet tests in explorer view modular to write wallet test…
JonathanConn Jul 19, 2023
07e9095
feat: tested web3modal using lab against our web3wallet example, adde…
JonathanConn Jul 23, 2023
21fe637
fix: minor cleanup, added tags to ui, added a test for chain switching
JonathanConn Jul 23, 2023
4aecdce
feat: Modularized modal and wallet pages by createing custom pages, a…
JonathanConn Jul 24, 2023
1ccbcbf
feat: started to split functional tests and ui tests apart, making it…
JonathanConn Jul 24, 2023
ddde48e
feat: finished refactor, test skeleton is now much more flexible and …
JonathanConn Jul 24, 2023
6614c80
fix: added remaining tests to suite, started experimenting with diffe…
JonathanConn Jul 25, 2023
da7fb2f
feat: finished basic validators, configuerd fixturers and tests to us…
JonathanConn Jul 25, 2023
7c58986
fix: regen package lock
JonathanConn Jul 25, 2023
47d4834
fix: removed workflow to reduce confusion, improved naming of validat…
JonathanConn Jul 31, 2023
47dfb2f
Merge branch 'V2' into feat/e2e-wallet
JonathanConn Jul 31, 2023
d42c8c7
feat: initial pipeline for testing
JonathanConn Aug 1, 2023
d6101cb
fix: added new deps
JonathanConn Aug 1, 2023
57767ae
fix: added build step
JonathanConn Aug 1, 2023
eb121ca
fix: added env to build
JonathanConn Aug 1, 2023
965c68c
fix: moved workflow to new file. Started testing cloudflare preview u…
JonathanConn Aug 1, 2023
cee2564
fix: switched CF zone ID to CF project ID to correctly use CF API
JonathanConn Aug 1, 2023
67de1ef
chore: switching run to test cf sol
JonathanConn Aug 1, 2023
0324688
chore: adding in cf url to playwright test env
JonathanConn Aug 1, 2023
f5879d0
fix: added missing env var
JonathanConn Aug 1, 2023
a01672d
fix: added missing env var
JonathanConn Aug 1, 2023
e79f92a
fix: fixed playwright config file + vars
JonathanConn Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/docs/dom-selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@
| w3m-text | `component-text` | W3M Text | `<span>` |
| w3m-modal-content | `component-modal-content` | W3M Content | `<main>` |
| w3m-modal-footer | `component-modal-footer` | W3M Footer | `<footer>` |
| w3m-modal-backcard | `component-modal-backcard` | W3M Backcard | `<div>` |
| w3m-modal-backcard | `component-modal-backcard` | W3M Backcard | `<div>` |
| w3m-modal-backcard | `backcard-help` | Help Button on Backcard | `<button>` |
| w3m-modal-backcard | `backcard-close` | Close Button on Backcard | `<buttong>` |
2 changes: 1 addition & 1 deletion .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
- name: install
run: npm ci
- name: check
run: npm run ${{ matrix.style-command }}
run: npm run ${{ matrix.style-command }}
55 changes: 55 additions & 0 deletions .github/workflows/pr_e2e_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: E2E tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you ignoring my previous PR feedback here?

Please either say you disagree with the feedback or agree with it but don't ignore it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not ignore your pervious feedback
This draft pr was never meant to be reviewed
I was using this PR to test solutions to an issue I linked in our slack
I agree with the changes you suggested and they will be there in the final version

on:
push:
branches:
- feat/e2e-pipeline

jobs:
e2e_tests:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
deployments: write
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: install deps
run: npm ci
- name: build
run: npm run build
env:
NEXT_PUBLIC_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_PROJECT_ID }}
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: cloudflare-preview-url
id: cloudflare_preview_url
uses: zentered/[email protected]
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
with:
cloudflare_project_id: ${{ secrets.CF_PROJECT_ID}}
wait_until_ready: true
- name: Get URL
run: echo "https://${{ steps.cloudflare_preview_url.outputs.preview_url }}"
- name: Run Playwright tests
working-directory: ./laboratory
run: npx playwright test
env:
LABS_URL: ${{ steps.cloudflare_preview_url.outputs.preview_url }}
WALLET_URL: "https://react-wallet.walletconnect.com/"
NEXT_PUBLIC_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_PROJECT_ID }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: ./laboratory/playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ out
lerna-debug.log
.env.local
.env
/test-results/
/playwright-report/
/playwright/.cache/
7 changes: 7 additions & 0 deletions laboratory/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Get your projectId at https://cloud.walletconnect.com
NEXT_PUBLIC_PROJECT_ID=""
NEXT_PUBLIC_SENTRY_DSN="" # OPTIONAL

# E2E test vars (optional)
LOCAL_LABS_URL="http://localhost:3000"
LOCAL_WALLET_URL="http://localhost:3001"

LABS_URL="https://labs.walletconnect.com"
WALLET_URL="https://react-wallet.walletconnect.com/"
4 changes: 4 additions & 0 deletions laboratory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
7 changes: 6 additions & 1 deletion laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
"private": true,
"scripts": {
"dev": "rm -rf .next; next dev",
"build": "next build"
"build": "next build",
"playwright:start": "next dev",
"playwright:install": "playwright install --with-deps",
"playwright:test": "playwright test",
"playwright:debug": "playwright test --debug"
},
"dependencies": {
"@nextui-org/react": "1.0.0-beta.13",
"@sentry/react": "7.60.0",
"@sentry/tracing": "7.60.0",
"@web3modal/ethereum": "2.7.1",
"@web3modal/react": "2.7.1",
"dotenv": "^16.3.1",
"next": "13.4.12",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
75 changes: 75 additions & 0 deletions laboratory/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { defineConfig, devices } from '@playwright/test'

import { config } from 'dotenv'
config({ path: './.env.local' })

export default defineConfig({
testDir: './tests',

fullyParallel: true,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'list',

expect: {
timeout: (process.env.CI ? 60 : 5) * 1000
},
timeout: 60 * 1000,

use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.CI ? process.env.LABS_URL : process.env.LOCAL_LABS_URL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',

video: process.env.CI ? 'off' : '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: 'npm run playwright:start',
url: process.env.CI ? process.env.LABS_URL : process.env.LOCAL_LABS_URL
}
})
5 changes: 4 additions & 1 deletion laboratory/src/components/NotificationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function NotificationModal() {
css={{ maxWidth: 900, margin: '0 auto' }}
>
<Modal.Header>
<Text h3>{title}</Text>
<Text h3 data-testid="notification-header">
{title}
</Text>
</Modal.Header>
<Modal.Body
css={{
Expand All @@ -24,6 +26,7 @@ export function NotificationModal() {
borderRadius: 16,
padding: 0
}}
data-testid="notification-body"
>
<pre>{body}</pre>
</Modal.Body>
Expand Down
8 changes: 6 additions & 2 deletions laboratory/src/components/WagmiWeb3ModalWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ export default function WagmiWeb3ModalWidget() {

{isConnected ? (
<>
<Button onPress={onSignMessage}>Sign Message</Button>
<Button onPress={onSignMessage} data-testid="lab-sign">
Sign Message
</Button>
<Spacer />
<Button onPress={onSignTypedData}>Sign Typed Data</Button>
<Button onPress={onSignTypedData} data-testid="lab-sign-typed">
Sign Typed Data
</Button>
</>
) : (
<>
Expand Down
7 changes: 7 additions & 0 deletions laboratory/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ const reactCards = [
link: '/with-wagmi/react-themed',
color: 'secondary',
libraries: ['@web3modal/react', '@web3modal/ethereum', 'wagmi', 'viem']
},
{
title: 'With Ethers Wagmi',
description: 'Wagmi playground using older deps with Ethers',
link: '/with-wagmi/react-ethers',
color: 'secondary',
libraries: ['@web3modal/react', '@web3modal/ethereum', 'wagmi', 'ethers']
}
] as const

Expand Down
8 changes: 8 additions & 0 deletions laboratory/tests/basic-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { testM, expect } from './shared/fixtures/w3m-fixture'

testM.describe('Modal only tests', () => {
testM('Should be able to open modal', async ({ modalPage }) => {
await modalPage.page.getByTestId('partial-core-connect-button').click()
await expect(modalPage.page.getByTestId('component-header-action-button')).toBeVisible()
})
})
11 changes: 11 additions & 0 deletions laboratory/tests/shared/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { SessionParams } from '../types'

export const DEFAULT_SESSION_PARAMS: SessionParams = {
reqAccounts: ['1', '2'],
optAccounts: ['1', '2'],
accept: true
}

// Will be moved to env vars in the future
export const LOCAL_LAB_URL = 'http://localhost:3000/with-wagmi/react'
export const LOCAL_WALLET_URL = 'http://localhost:3001'
6 changes: 6 additions & 0 deletions laboratory/tests/shared/fixtures/fixture.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { testMW, expect } from './w3m-wallet-fixture'

testMW('Open pages', ({ modalPage, walletPage }) => {
expect(modalPage).toBeDefined()
expect(walletPage).toBeDefined()
})
23 changes: 23 additions & 0 deletions laboratory/tests/shared/fixtures/w3m-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test as base } from '@playwright/test'
import { ModalPage } from '../pages/ModalPage'
import { ModalValidator } from '../validators/ModalValidator'

// Declare the types of fixtures to use
interface ModalFixture {
modalPage: ModalPage
modalValidator: ModalValidator
}

// M -> test Modal
export const testM = base.extend<ModalFixture>({
modalPage: async ({ page }, use) => {
const modalPage = new ModalPage(page)
await modalPage.load()
await use(modalPage)
},
modalValidator: async ({ modalPage }, use) => {
const modalValidator = new ModalValidator(modalPage.page)
await use(modalValidator)
}
})
export { expect } from '@playwright/test'
29 changes: 29 additions & 0 deletions laboratory/tests/shared/fixtures/w3m-wallet-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { testM as base } from './w3m-fixture'
import { WalletPage } from '../pages/WalletPage'
import { WalletValidator } from '../validators/WalletValidator'

// Declare the types of fixtures to use
interface ModalWalletFixture {
walletPage: WalletPage
walletValidator: WalletValidator
}

// MW -> test Modal + Wallet
export const testMW = base.extend<ModalWalletFixture>({
walletPage: async ({ context, browserName }, use) => {
// WalletPage needs clipboard permissions with chromium to paste URI
if (browserName === 'chromium') {
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
}

// Use a new page, to open alongside the modal
const walletPage = new WalletPage(await context.newPage())
await walletPage.load()
await use(walletPage)
},
walletValidator: async ({ walletPage }, use) => {
const walletValidator = new WalletValidator(walletPage.page)
await use(walletValidator)
}
})
export { expect } from '@playwright/test'
48 changes: 48 additions & 0 deletions laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { Locator, Page } from '@playwright/test'
import { LOCAL_LAB_URL } from '../constants'

export class ModalPage {
private readonly baseURL = LOCAL_LAB_URL

private readonly w3modal: Locator

constructor(public readonly page: Page) {
this.w3modal = this.page.getByTestId('partial-core-connect-button')
}

async load() {
await this.page.goto(this.baseURL)
}

async getUri() {
await this.page.goto(this.baseURL)
await this.w3modal.click()
await this.page.getByTestId('component-header-action-button').click()
}

async disconnect() {
await this.page.getByTestId('partial-account-address').click()
await this.page.getByTestId('view-account-disconnect-button').click()
}

async sign() {
await this.page.getByTestId('lab-sign').click()
}

async signTyped() {
await this.page.getByTestId('lab-sign-typed').click()
}

async switchChain({ chainName }: { chainName: string }) {
await this.page.getByTestId('partial-network-switch-button').click()
await this.page.getByText(new RegExp(chainName, 'u')).click()
}

async helpModal() {
await this.page.getByTestId('backcard-help').click()
}

async closeModal() {
await this.page.getByTestId('backcard-close').click()
}
}
Loading
Loading