Skip to content

Commit

Permalink
add playwright for e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 6, 2024
1 parent 6c8f798 commit 4575e1c
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 11 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Playwright Tests

on:
push:
branches:
- main
- development
- noah/playwright
pull_request:
branches:
- main
- development
- noah/playwright

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn
- run: yarn install
- name: Install Playwright browsers
run: yarn playwright install --with-deps
- name: Run Playwright tests
run: yarn test:e2e
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: apps/dapp/playwright-report/
retention-days: 30
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ node_modules/
out/

.env
.env.development.local
.env.local
.env.production.local
.env.test.local
.env*.local

*.swo
*.swp
Expand All @@ -28,3 +25,9 @@ out/
\#*\#

.turbo

# playwright
test-results/
playwright-report/
blob-report/
playwright/.cache/
4 changes: 4 additions & 0 deletions apps/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"start": "next start",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"test:e2e": "cp .env.testnet .env && playwright test",
"ts": "tsc --noEmit --incremental",
"ts:watch": "ts --watch"
},
Expand Down Expand Up @@ -53,12 +54,15 @@
"devDependencies": {
"@dao-dao/config": "2.4.0-rc.8",
"@next/bundle-analyzer": "^14.1.0",
"@playwright/test": "^1.44.1",
"@sentry/cli": "^2.21.3",
"@solana/web3.js": "^1.75.0",
"@types/cors": "^2.8.13",
"@types/lodash.clonedeep": "^4.5.0",
"@types/node": "^20.14.2",
"@types/react": "^17.0.37",
"autoprefixer": "^9.8.6",
"dotenv": "^16.4.5",
"eslint": "^8.23.1",
"eslint-plugin-header": "^3.1.1",
"next-i18next": "^11.0.0",
Expand Down
87 changes: 87 additions & 0 deletions apps/dapp/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.
import { defineConfig, devices } from '@playwright/test'
import dotenv from 'dotenv'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
dotenv.config()

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* 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' },
// },
],

/* Build and run server before starting the tests */
webServer: {
command: 'yarn build && yarn start',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
// allow 10 minutes for the server to build
timeout: 10 * 60 * 1000,
},

expect: {
// Default expect timeout to 20 seconds.
timeout: 20 * 1000,
},
})
21 changes: 21 additions & 0 deletions apps/dapp/tests/create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

import { expect, test } from '@playwright/test'

import './setup'

test('create DAO page renders', async ({ page }) => {
await page.goto('/dao/create')

// Expect "New DAO" header to exist.
await expect(
page.locator('div.header-text').filter({ hasText: 'New DAO' }).first()
).toBeVisible()

// Expect "Log in" button to exist.
await expect(page.getByRole('button', { name: 'Log in' })).toBeVisible()

// Expect "Continue" button to exist.
await expect(page.getByRole('button', { name: 'Continue' })).toBeVisible()
})
110 changes: 110 additions & 0 deletions apps/dapp/tests/dao.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

import { expect, test } from '@playwright/test'

import './setup'

test('DAO home tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()
})

test('DAO proposals tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4/proposals'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()

// Expect "New proposal" button to exist.
await expect(page.getByText('New proposal', { exact: true })).toBeVisible()
})

test('DAO treasury tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4/treasury'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()

// Expect "Copy address" button to exist.
await expect(page.getByText('Copy address', { exact: true })).toBeVisible()

// Expect "Tokens" title to exist.
await expect(page.getByText('Tokens', { exact: true })).toBeVisible()
})

test('DAO subDAOs tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4/subdaos'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()

// Expect "New SubDAO" button to exist.
await expect(page.getByText('New SubDAO', { exact: true })).toBeVisible()
})

test('DAO members tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4/members'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()

// Expect member voting power title to exist.
await expect(
page.getByText('Voting power', { exact: true }).first()
).toBeVisible()
})

test('DAO apps tab renders', async ({ page }) => {
await page.goto(
'/dao/juno1vh0xndu9pj8g0lat6k3500mxusfduh804sf9hj7jpt4kgj0gmreq3jmqj4/apps'
)

// Expect no 404 error.
await expect(page.getByText('404: Not Found')).not.toBeVisible({
timeout: 5000,
})

// Expect description to exist.
await expect(page.getByText('Worship the moon.')).toBeVisible()

// Expect member voting power title to exist.
await expect(page.getByRole('button', { name: 'Go' }).first()).toBeVisible()
})
36 changes: 36 additions & 0 deletions apps/dapp/tests/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

import { expect, test } from '@playwright/test'

import './setup'

test('home page renders', async ({ page }) => {
await page.goto('/')

// Expect "Log in" button to exist.
await expect(page.getByRole('button', { name: 'Log in' })).toBeVisible()

// Expect "Chain governance" title to exist.
await expect(
page.getByText('Chain governance', { exact: true })
).toBeVisible()

// Expect "Featured DAOs" title to exist.
await expect(page.getByText('Featured DAOs', { exact: true })).toBeVisible()
})

test('chain-specific home page renders', async ({ page }) => {
await page.goto('/juno')

// Expect "Log in" button to exist.
await expect(page.getByRole('button', { name: 'Log in' })).toBeVisible()

// Expect "Chain governance" title to exist.
await expect(
page.getByText('Chain governance', { exact: true })
).toBeVisible()

// Expect "Featured DAOs" title to exist.
await expect(page.getByText('Featured DAOs', { exact: true })).toBeVisible()
})
16 changes: 16 additions & 0 deletions apps/dapp/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

/**
* Set up tests.
*/

import { test } from '@playwright/test'

test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
// Mark beta warning as approved so it doesn't appear and block the rest of
// the page.
window.localStorage.setItem('betaWarningAccepted', 'true')
})
})
15 changes: 15 additions & 0 deletions apps/dapp/tests/status.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

import { expect, test } from '@playwright/test'

import './setup'

test('status page renders', async ({ page }) => {
await page.goto('/status')

// Expect "Status" header to exist.
await expect(
page.locator('p.header-text').filter({ hasText: 'Status' })
).toBeVisible()
})
9 changes: 7 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// GNU AFFERO GENERAL PUBLIC LICENSE Version 3. Copyright (C) 2022 DAO DAO Contributors.
// See the "LICENSE" file in the root directory of this package for more copyright information.

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
moduleDirectories: ['node_modules', '<rootDir>'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
testPathIgnorePatterns: [
'<rootDir>/.next/',
'<rootDir>/node_modules/',
// playwright e2e tests, not jest. jest unit tests are spread throughout
'<rootDir>/apps/dapp/tests/'
],
preset: 'ts-jest',
testEnvironment: 'node',
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"format": "prettier --write \"**/*.{css,json,md}\" && turbo run format --continue --parallel",
"lint": "prettier --check \"**/*.{css,json,md}\" && turbo run lint --continue --parallel",
"test": "jest",
"test:e2e": "yarn dapp test:e2e",
"dapp": "yarn workspace @dao-dao/dapp",
"sda": "yarn workspace @dao-dao/sda",
"i18n": "yarn workspace @dao-dao/i18n",
Expand Down
Loading

0 comments on commit 4575e1c

Please sign in to comment.