mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 20:06:57 +02:00
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>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { defineConfig, devices } from '@playwright/test';
|
|
import { STORAGE_STATE_FILE } from './tests/e2e/global-setup';
|
|
|
|
export default defineConfig({
|
|
testDir: './tests/e2e',
|
|
fullyParallel: true,
|
|
forbidOnly: !!process.env.CI,
|
|
retries: 0,
|
|
workers: process.env.CI ? 4 : undefined,
|
|
reporter: 'html',
|
|
globalSetup: './tests/e2e/global-setup.ts',
|
|
use: {
|
|
baseURL: 'http://localhost:4173',
|
|
trace: 'on-first-retry',
|
|
screenshot: 'only-on-failure',
|
|
serviceWorkers: 'block'
|
|
},
|
|
projects: [
|
|
{
|
|
name: 'auth-setup',
|
|
testMatch: 'auth.spec.ts',
|
|
fullyParallel: false,
|
|
use: { ...devices['Desktop Chrome'] }
|
|
},
|
|
{
|
|
// Logs in once and saves the session cookie for the `app` project.
|
|
name: 'login-state',
|
|
testMatch: 'auth.setup.ts',
|
|
dependencies: ['auth-setup'],
|
|
use: { ...devices['Desktop Chrome'] }
|
|
},
|
|
{
|
|
name: 'app',
|
|
testIgnore: ['auth.spec.ts', 'auth.setup.ts'],
|
|
dependencies: ['login-state'],
|
|
// Every context starts with the admin already logged in. Specs that
|
|
// need an unauthenticated baseline opt out with
|
|
// `test.use({ storageState: { cookies: [], origins: [] } })`.
|
|
use: { ...devices['Desktop Chrome'], storageState: STORAGE_STATE_FILE }
|
|
}
|
|
],
|
|
webServer: {
|
|
// The wipe runs here (before the server opens the database), not in
|
|
// globalSetup: Playwright starts the webServer before globalSetup, so
|
|
// deleting the SQLite files later would orphan the server's open
|
|
// database onto a deleted inode. Tests that read the database file
|
|
// directly (see linkUserToOAuth in admin-users.spec.ts) must see the
|
|
// server's real database file.
|
|
command:
|
|
'rm -f data/test-crumbs.db data/test-crumbs.db-wal data/test-crumbs.db-shm data/test-crumbs.db-journal && pnpm preview --port 4173',
|
|
port: 4173,
|
|
reuseExistingServer: !process.env.CI,
|
|
timeout: 120_000,
|
|
env: {
|
|
DATABASE_URL: './data/test-crumbs.db',
|
|
NODE_ENV: 'test'
|
|
}
|
|
}
|
|
});
|