Skip to content

Commit 9d4e438

Browse files
committed
chore: add global setup to warm up dev server and limit playwright concurrency to prevent flaky tests
1 parent bcd2e0b commit 9d4e438

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

www/e2e/global-setup.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { chromium } from '@playwright/test'
2+
3+
const baseURL = 'http://127.0.0.1:3000'
4+
5+
/**
6+
* Warm up the dev server before the tests run. A cold `vite dev` boot
7+
* recompiles the whole app (SSR + client) on first request, and the first
8+
* browser to load the client modules also triggers dependency re-optimization,
9+
* which can take well over a minute and stall the first test. Loading both
10+
* surfaces here (real browser, real module requests) absorbs that cost once,
11+
* up front, instead of inside a test.
12+
*/
13+
export default async function globalSetup() {
14+
const browser = await chromium.launch()
15+
const page = await browser.newPage()
16+
17+
await page.goto(`${baseURL}/`, { waitUntil: 'domcontentloaded' })
18+
await page
19+
.getByRole('heading', { level: 1 })
20+
.first()
21+
.waitFor({ state: 'visible', timeout: 120_000 })
22+
23+
await page.goto(`${baseURL}/admin`, { waitUntil: 'domcontentloaded' })
24+
await page
25+
.getByRole('heading', { name: 'Sign in' })
26+
.waitFor({ state: 'visible', timeout: 120_000 })
27+
28+
await browser.close()
29+
}

www/playwright.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { defineConfig } from '@playwright/test'
22

33
export default defineConfig({
44
testDir: './e2e',
5-
fullyParallel: true,
5+
// Serial, single worker: the first page load after a cold `vite dev` boot
6+
// recompiles the whole app (SSR + client) and the Cloudflare module
7+
// runner is fragile under concurrent cold loads, so hitting it with
8+
// parallel workers makes the first run flaky.
9+
workers: 1,
10+
retries: 1,
11+
globalSetup: './e2e/global-setup',
612
reporter: 'list',
713
use: {
814
baseURL: 'http://127.0.0.1:3000',

0 commit comments

Comments
 (0)