mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 12:06:57 +02:00
perf(e2e): log in once and share the admin session via storage state
Every test in the `app` project submitted the login form through the authenticatedPage fixture: a page load, an Argon2 verification on the server, a redirect and a networkidle wait. Over 137 tests that was roughly half of the median test's 1.8s. A new `login-state` setup project (tests/e2e/auth.setup.ts) authenticates once after auth.spec has created the account and saves the session cookie to data/test-storage-state.json. The `app` project loads it into every context, so setupAndLogin takes its "session still valid" path and the fixture is reduced to a page load. pwa.spec and mcp.spec describe anonymous visitors and opt out with an empty storageState so their baseline is unchanged. Local run, 4 workers: summed test time 276s -> 256s, median 1.8s -> 1.6s. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
committed by
Fred Cabassut
co-authored by
Claude Fable 5.1
parent
af7186675e
commit
7bf06edd97
@@ -219,6 +219,7 @@ Write tests first or alongside features. Tests serve as living documentation of
|
||||
- Config: `playwright.config.ts` (Chromium only, builds + previews app on port 4173)
|
||||
- Test database: `./data/test-crumbs.db` (cleaned via `global-setup.ts`)
|
||||
- Auth fixture: `tests/e2e/helpers/fixtures.ts` provides `authenticatedPage` (handles setup/login race conditions across parallel workers)
|
||||
- **Shared login state**: `tests/e2e/auth.setup.ts` (project `login-state`) logs in once and saves the admin session cookie to `data/test-storage-state.json`; the `app` project loads it into every context so tests start authenticated instead of submitting the login form each time. A spec that needs an anonymous baseline opts out with `test.use({ storageState: { cookies: [], origins: [] } })` (see `pwa.spec.ts`, `mcp.spec.ts`). Never write a test that revokes or logs out the admin's own session — it would break every test in other workers
|
||||
- Auth tests use `test.describe.serial` because they depend on sequential database state
|
||||
- **Offline/online tests**: After `setOffline(false)`, always manually dispatch the `online` event via `page.evaluate(() => window.dispatchEvent(new Event('online')))` — Playwright doesn't reliably emit it in headless/CI environments, causing flaky `waitForResponse` timeouts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user