Skip to content

Commit 59ab423

Browse files
committed
chore: setup playwright
1 parent da3e1e5 commit 59ab423

File tree

7 files changed

+159
-1
lines changed

7 files changed

+159
-1
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,41 @@ jobs:
4848
- name: Check formatting of everything (prettier)
4949
run: |
5050
npm run fmt
51+
52+
e2e-test:
53+
name: E2E Tests (Playwright)
54+
timeout-minutes: 60
55+
# run only if triggered by push on a branch or by a PR event for a PR which is not a draft
56+
if: ${{ !github.event.pull_request || github.event.pull_request.draft == false }}
57+
runs-on: ubuntu-24.04
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Install Node.js
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version-file: ".nvmrc"
65+
cache: npm
66+
67+
- name: Install dependencies
68+
run: |
69+
npm ci
70+
71+
- name: Install Playwright Browsers
72+
run: |
73+
npx playwright install --with-deps
74+
75+
- name: Start the server
76+
run: |
77+
npm run start &
78+
79+
- name: Run Playwright tests
80+
run: |
81+
npm run test:e2e
82+
83+
- uses: actions/upload-artifact@v4
84+
if: ${{ !cancelled() }}
85+
with:
86+
name: playwright-report
87+
path: playwright-report/
88+
retention-days: 30

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ next-env.d.ts
5858
npm-debug.log*
5959
yarn-debug.log*
6060
yarn-error.log*
61+
62+
# Playwright
63+
/test-results/
64+
/playwright-report/
65+
/blob-report/
66+
/playwright/.cache/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Open [http://localhost:5173](http://localhost:5173) with your browser to see the
2828

2929
- `npm run start`: Starts the development server.
3030
- `npm run build`: Builds the app for production.
31+
- `npm run test:e2e:update`: Runs all End-to-End tests and updates the screenshots/snapshots.
3132

3233
## Configuration
3334

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"lint:js": "eslint --max-warnings 0 .",
1919
"lint:fix:js": "eslint --max-warnings 0 . --fix",
2020
"fmt": "prettier --check .",
21-
"fmt:fix": "prettier --write ."
21+
"fmt:fix": "prettier --write .",
22+
"test:e2e": "playwright test",
23+
"test:e2e:update": "playwright test --update-snapshots"
2224
},
2325
"lint-staged": {
2426
"**/*.{ts,tsx,jsx,js}": [
@@ -77,6 +79,7 @@
7779
"zustand": "^4.5.4"
7880
},
7981
"devDependencies": {
82+
"@playwright/test": "^1.51.1",
8083
"@types/eslint-scope": "^3.7.7",
8184
"@types/espree": "^10.0.0",
8285
"@types/esquery": "^1.5.4",

playwright.config.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: "./e2e-tests",
8+
fullyParallel: true,
9+
forbidOnly: !!process.env.CI,
10+
retries: process.env.CI ? 1 : 0,
11+
reporter: process.env.CI ? [["html"], ["github"]] : "html",
12+
13+
use: {
14+
baseURL: "http://127.0.0.1:5173",
15+
16+
/* Capture trace and video on first retry (retries are only done in CI) */
17+
trace: "on-first-retry",
18+
video: "on-first-retry",
19+
},
20+
21+
expect: {
22+
toHaveScreenshot: {
23+
/* Screenshots are never exactly the same for various reasons - allow a small amount of pixel difference */
24+
maxDiffPixelRatio: 0.05,
25+
},
26+
},
27+
28+
projects: [
29+
{
30+
name: "chromium",
31+
use: { ...devices["Desktop Chrome"] },
32+
},
33+
{
34+
name: "firefox",
35+
use: { ...devices["Desktop Firefox"] },
36+
},
37+
{
38+
name: "webkit",
39+
use: { ...devices["Desktop Safari"] },
40+
},
41+
],
42+
});

vite.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ export default defineConfig({
1818
define: {
1919
"process.env.NODE_DEBUG": JSON.stringify(process.env.NODE_DEBUG),
2020
},
21+
server: {
22+
// accept connections on 127.0.0.1 because "localhost" is not resolved correctly by Playwright in CI
23+
host: "127.0.0.1",
24+
},
2125
});

0 commit comments

Comments
 (0)