Skip to content

Commit cbbc0e1

Browse files
committed
feat: add commands to run playwright
1 parent f744999 commit cbbc0e1

File tree

14 files changed

+139
-562
lines changed

14 files changed

+139
-562
lines changed

.changeset/smart-cars-promise.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"e2e-tests": major
3+
---
4+
5+
- Implemented Playwright for automated browser testing in (#1046)[https://github.com/IFRCGo/go-web-app/issues/1046]
6+
- Added CLI commands to run Playwright tests in (#1047)[https://github.com/IFRCGo/go-web-app/issues/1047]
7+
- Integrated Playwright tests into CI pipeline (#1048)[https://github.com/IFRCGo/go-web-app/issues/1048]

.github/workflows/playwright.yml

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
name: Playwright Tests
2+
3+
env:
4+
APP_BASE_URL: ${{ vars.APP_BASE_URL }}
5+
26
on:
37
push:
4-
branches: [ develop ]
8+
branches:
9+
- develop
10+
- 'project/playwright'
511
pull_request:
6-
branches: [ develop ]
12+
branches:
13+
- develop
14+
- 'project/playwright'
15+
# Allows you to run this workflow manually from the Actions tab
16+
workflow_dispatch:
17+
18+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
724
jobs:
825
test-e2e:
926
name: Playwright e2e test
27+
environment: 'test'
1028
timeout-minutes: 60
1129
runs-on: ubuntu-latest
1230
defaults:
1331
run:
14-
working-directory: packages/tests-e2e
32+
working-directory: packages/e2e-tests
1533
steps:
1634
- uses: actions/checkout@v4
1735
- uses: actions/setup-node@v4
@@ -24,8 +42,30 @@ jobs:
2442
- name: Run Playwright tests
2543
run: yarn playwright test
2644
- uses: actions/upload-artifact@v4
27-
if: always()
45+
id: playwright-report-artifact
46+
if: ${{ !cancelled() }}
2847
with:
2948
name: playwright-report
30-
path: playwright-report/
31-
retention-days: 30
49+
path: ./packages/e2e-tests/playwright-report/
50+
- uses: actions/upload-pages-artifact@v3
51+
id: playwright-report-github-pages-artifact
52+
if: ${{ !cancelled() }}
53+
with:
54+
name: github-pages
55+
path: ./packages/e2e-tests/playwright-report/
56+
deploy:
57+
name: Upload Playwright Report to GitHub Pages
58+
needs: test-e2e
59+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
60+
permissions:
61+
contents: read
62+
pages: write
63+
id-token: write
64+
environment:
65+
name: github-pages
66+
url: ${{ steps.deployment.outputs.page_url }}
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Deploy to Github Pages
70+
id: deployment
71+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ build-ssr
2424
*.njsproj
2525
*.sln
2626
*.sw?
27-
2827
.env*
2928
!.env.example
3029
.eslintcache
@@ -41,3 +40,7 @@ storybook-static/
4140

4241
# Helm
4342
.helm-charts/
43+
44+
#tests
45+
test-results/
46+

app/.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
APP_TITLE=IFRC GO
2+
APP_ENVIRONMENT=testing
3+
APP_API_ENDPOINT=
4+
APP_ADMIN_URL=
5+
APP_SHOW_ENV_BANNER=
6+
7+
# Mapbox
8+
APP_MAPBOX_ACCESS_TOKEN=
9+
10+
# TinyMCE
11+
APP_TINY_API_KEY=
12+
13+
# GO Risk Server
14+
APP_RISK_API_ENDPOINT=
15+
16+
# Sentry
17+
APP_SENTRY_DSN=
18+
APP_SENTRY_TRACES_SAMPLE_RATE=
19+
APP_SENTRY_REPLAYS_SESSION_SAMPLE_RATE=
20+
APP_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE=
21+
# Google Analytics
22+
APP_GOOGLE_ANALYTICS_ID=

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"preview": "pnpm -F go-web-app preview",
1919
"storybook": "pnpm -F go-ui-storybook storybook",
2020
"build-storybook": "pnpm -F go-ui-storybook build-storybook",
21-
"chromatic": "pnpm -F go-ui-storybook chromatic"
21+
"chromatic": "pnpm -F go-ui-storybook chromatic",
22+
"test:e2e": "yarn workspace e2e-tests playwright test"
2223
},
2324
"devDependencies": {
2425
"knip": "^5.36.3"

packages/e2e-tests/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Playwright Base URL
2+
APP_BASE_URL=
File renamed without changes.

packages/tests-e2e/biome.json renamed to packages/e2e-tests/biome.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
"recommended": true
1010
}
1111
},
12-
"formatter": {
13-
"indentStyle": "space",
14-
"indentWidth": 4
12+
"javascript": {
13+
"formatter": {
14+
"indentStyle": "space",
15+
"quoteStyle": "single",
16+
"indentWidth": 4
17+
}
1518
}
1619
}

packages/e2e-tests/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "e2e-tests",
3+
"version": "0.0.1",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"devDependencies": {
7+
"@biomejs/biome": "1.7.3",
8+
"@playwright/test": "^1.44.0",
9+
"@types/node": "^20.12.12"
10+
},
11+
"scripts": {
12+
"install": "playwright install",
13+
"test": "playwright test",
14+
"format": "biome format --write ./tests/*",
15+
"lint": "yarn biome lint --apply ./tests/*",
16+
"biome:check": "biome check --apply ./tests/*"
17+
},
18+
"dependencies": {
19+
"dotenv": "^16.4.5"
20+
}
21+
}

packages/tests-e2e/playwright.config.ts renamed to packages/e2e-tests/playwright.config.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { defineConfig, devices } from "@playwright/test";
2-
import "dotenv/config";
1+
import { defineConfig, devices } from '@playwright/test';
2+
import 'dotenv/config';
33

44
/**
55
* Read environment variables from file.
66
* https://github.com/motdotla/dotenv
77
*/
8-
// require('dotenv').config();
8+
require('dotenv').config();
99

1010
/**
1111
* See https://playwright.dev/docs/test-configuration.
1212
*/
1313
export default defineConfig({
14-
testDir: "./tests",
14+
testDir: './tests',
1515
/* Run tests in files in parallel */
1616
fullyParallel: true,
1717
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -21,31 +21,31 @@ export default defineConfig({
2121
/* Opt out of parallel tests on CI. */
2222
workers: process.env.CI ? 1 : undefined,
2323
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24-
reporter: "html",
24+
reporter: 'html',
2525
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2626
use: {
2727
/* Base URL to use in actions like `await page.goto('/')`. */
2828
baseURL: process.env.APP_BASE_URL,
2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30-
trace: "on-first-retry",
30+
trace: 'on-first-retry',
3131
},
3232

3333
/* Configure projects for major browsers */
3434
projects: process.env.CI
3535
? [
3636
{
37-
name: "chromium",
38-
use: { ...devices["Desktop Chrome"] },
37+
name: 'chromium',
38+
use: { ...devices['Desktop Chrome'] },
3939
},
4040

4141
{
42-
name: "firefox",
43-
use: { ...devices["Desktop Firefox"] },
42+
name: 'firefox',
43+
use: { ...devices['Desktop Firefox'] },
4444
},
4545

4646
{
47-
name: "webkit",
48-
use: { ...devices["Desktop Safari"] },
47+
name: 'webkit',
48+
use: { ...devices['Desktop Safari'] },
4949
},
5050

5151
/* Test against mobile viewports. */
@@ -71,13 +71,13 @@ export default defineConfig({
7171
: [
7272
// NOTE: WebKit is only supported on Debian and Ubuntu in Playwright.
7373
{
74-
name: "chromium",
75-
use: { ...devices["Desktop Chrome"] },
74+
name: 'chromium',
75+
use: { ...devices['Desktop Chrome'] },
7676
},
7777

7878
{
79-
name: "firefox",
80-
use: { ...devices["Desktop Firefox"] },
79+
name: 'firefox',
80+
use: { ...devices['Desktop Firefox'] },
8181
},
8282
],
8383

0 commit comments

Comments
 (0)