Skip to content

Commit

Permalink
Set up Playwright
Browse files Browse the repository at this point in the history
Breaking changes were merged to the app that caused it to be unable to
boot up. We didn't notice this until someone tried to load up the
deployed site. Non-major Renovate dependency PRs are merged
automatically on this repo, which is risky without at least minimal
automated testing. We had a CI workflow to test that the app built but
this evidently wasn't sufficient. This adds Playwright so that we can do
a basic 'homepage loads' kind of end-to-end test, and run this on CI for
pull requests and pushes to main
  • Loading branch information
yndajas committed Nov 6, 2024
1 parent edb51cb commit d1c6eab
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 22 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/ci.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: End-to-end tests
on:
pull_request:
push:
branches: [ main ]
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 ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ node_modules/
/cypress/temp
tmp/
package-lock.json
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
60 changes: 56 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
"hmrc-frontend": "^6.0.0",
"jquery": "3.7.1",
"notifications-node-client": "5.2.3"
},
"devDependencies": {
"@playwright/test": "^1.48.2",
"@types/node": "^22.9.0"
}
}
48 changes: 48 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = 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'] },
},
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run dev',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
});

0 comments on commit d1c6eab

Please sign in to comment.