Skip to content

Commit 4aff703

Browse files
committed
chore: run tests via Docker container to produce consistent screenshots
1 parent fd2a68c commit 4aff703

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ jobs:
6868
run: |
6969
npm ci
7070
71-
- name: Install Playwright Browsers
72-
run: |
73-
npx playwright install --with-deps
74-
7571
- name: Run Playwright tests
7672
run: |
7773
npm run test:e2e

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"lint:fix:js": "eslint --max-warnings 0 . --fix",
2020
"fmt": "prettier --check .",
2121
"fmt:fix": "prettier --write .",
22-
"test:e2e": "playwright test",
23-
"test:e2e:update": "playwright test --update-snapshots"
22+
"test:e2e": "PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/ playwright test",
23+
"test:e2e:update": "npm run test:e2e -- --update-snapshots"
2424
},
2525
"lint-staged": {
2626
"**/*.{ts,tsx,jsx,js}": [

playwright.config.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
reporter: process.env.CI ? [["html"], ["github"]] : "html",
1212

1313
use: {
14-
baseURL: "http://127.0.0.1:5173",
14+
baseURL: `http://${process.env.CI ? "localhost" : "host.docker.internal"}:5173`,
1515

1616
// ensure consistent timezone and locale
1717
timezoneId: "America/Los_Angeles",
@@ -48,9 +48,22 @@ export default defineConfig({
4848
},
4949
],
5050

51-
webServer: {
52-
command: "npm run start",
53-
url: "http://127.0.0.1:5173",
54-
reuseExistingServer: !process.env.CI,
55-
},
51+
webServer: [
52+
{
53+
command: `docker run ${process.env.CI ? "--network host" : "--add-host=host.docker.internal:host-gateway"} -p 3000:3000 --rm --init --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.51.1-noble /bin/sh -c "npx -y [email protected] run-server --port 3000 --host 0.0.0.0"`,
54+
url: "http://127.0.0.1:3000/",
55+
stdout: "pipe",
56+
stderr: "pipe",
57+
gracefulShutdown: {
58+
signal: "SIGTERM",
59+
timeout: 10_000,
60+
},
61+
reuseExistingServer: !process.env.CI,
62+
},
63+
{
64+
command: "npm run start",
65+
url: "http://127.0.0.1:5173",
66+
reuseExistingServer: !process.env.CI,
67+
},
68+
],
5669
});

vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineConfig({
1919
"process.env.NODE_DEBUG": JSON.stringify(process.env.NODE_DEBUG),
2020
},
2121
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",
22+
// accept connections from everywhere because Playwright browsers run from within a Docker container which has some random IP
23+
host: "0.0.0.0",
2424
},
2525
});

0 commit comments

Comments
 (0)