|
1 | 1 | /// <reference types="node" /> |
2 | | -import { defineConfig, devices } from '@playwright/test'; |
| 2 | +import { defineConfig, devices } from "@playwright/test"; |
| 3 | + |
| 4 | +const onCI = !!process.env.CI; |
3 | 5 |
|
4 | 6 | /** |
5 | | - * See https://playwright.dev/docs/test-configuration. |
| 7 | + * CI uses a production Node build — `vite dev` on Ubuntu runners was serving |
| 8 | + * SSR HTML while client modules never hydrated enough to call /api/teams. |
| 9 | + * Local keeps `vite dev` for fast iteration. |
6 | 10 | */ |
| 11 | +const webServerCommand = onCI |
| 12 | + ? "pnpm build && PORT=5173 HOST=127.0.0.1 ORIGIN=http://127.0.0.1:5173 node build" |
| 13 | + : process.platform === "win32" |
| 14 | + ? "pnpm dev" |
| 15 | + : "PLAYWRIGHT_E2E=1 pnpm dev"; |
| 16 | + |
7 | 17 | export default defineConfig({ |
8 | | - testDir: './tests', |
9 | | - globalSetup: './tests/global-setup.ts', |
| 18 | + testDir: "./tests", |
| 19 | + globalSetup: "./tests/global-setup.ts", |
10 | 20 | fullyParallel: true, |
11 | | - forbidOnly: !!process.env.CI, |
12 | | - retries: process.env.CI ? 2 : 0, |
13 | | - workers: process.env.CI ? 1 : undefined, |
14 | | - // Cold `vite dev` on CI can take >15s before client effects fire /api/teams. |
| 21 | + forbidOnly: onCI, |
| 22 | + retries: onCI ? 2 : 0, |
| 23 | + workers: onCI ? 1 : undefined, |
15 | 24 | timeout: 60_000, |
16 | 25 | expect: { |
17 | | - timeout: process.env.CI ? 30_000 : 10_000, |
| 26 | + timeout: onCI ? 30_000 : 10_000, |
18 | 27 | }, |
19 | | - reporter: 'html', |
| 28 | + reporter: "html", |
20 | 29 | use: { |
21 | | - baseURL: 'http://localhost:5173', |
22 | | - trace: 'on-first-retry', |
23 | | - serviceWorkers: 'block', |
| 30 | + baseURL: "http://127.0.0.1:5173", |
| 31 | + trace: "on-first-retry", |
| 32 | + serviceWorkers: "block", |
24 | 33 | navigationTimeout: 60_000, |
25 | 34 | }, |
26 | 35 |
|
27 | 36 | projects: [ |
28 | 37 | { |
29 | | - name: 'chromium', |
30 | | - use: { ...devices['Desktop Chrome'] }, |
| 38 | + name: "chromium", |
| 39 | + use: { ...devices["Desktop Chrome"] }, |
31 | 40 | }, |
32 | 41 | ], |
33 | 42 |
|
34 | 43 | webServer: { |
35 | | - // Inline env so PLAYWRIGHT_E2E is set before Vite snapshots process.env |
36 | | - // (Kit's $env/dynamic/private is config-time; we also read process.env live). |
37 | | - command: |
38 | | - process.platform === 'win32' |
39 | | - ? 'pnpm dev' |
40 | | - : 'PLAYWRIGHT_E2E=1 pnpm dev', |
41 | | - url: 'http://localhost:5173', |
42 | | - // Only reuse a server that was already started with PLAYWRIGHT_E2E=1. |
43 | | - // A plain `pnpm dev` would miss SSR fixtures and greenwash false failures. |
44 | | - reuseExistingServer: |
45 | | - !process.env.CI && process.env.PLAYWRIGHT_E2E === '1', |
46 | | - timeout: 120_000, |
| 44 | + command: webServerCommand, |
| 45 | + url: "http://127.0.0.1:5173", |
| 46 | + reuseExistingServer: !onCI && process.env.PLAYWRIGHT_E2E === "1", |
| 47 | + timeout: 180_000, |
47 | 48 | env: { |
48 | 49 | ...process.env, |
49 | | - PLAYWRIGHT_E2E: '1', |
| 50 | + PLAYWRIGHT_E2E: "1", |
| 51 | + PLAYWRIGHT_DEBUG_NET: onCI ? "1" : process.env.PLAYWRIGHT_DEBUG_NET ?? "", |
50 | 52 | }, |
51 | 53 | }, |
52 | 54 | }); |
0 commit comments