playwright.config.ts
Rama main · réplica de lectura del repositorio original.
import { mkdtempSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { defineConfig, devices } from '@playwright/test'
import type { RealmrootOptions } from './e2e/fixtures'
// E2E runs against the real stack: `vite dev --mode e2e` serves the SPA + the
// Worker against an ISOLATED local D1 (CF_PERSIST_STATE_PATH, separate from
// `pnpm dev`'s state). The DB is reset + migrated by the global setup before the
// suite, and the suite is stateful (it drives onboarding), so it runs serially.
// The readiness probe is `/api/health`, which the Worker answers without a DB
// read, so it goes green before globalSetup migrates. Only hermetic journeys
// live here — no external dependency, just SPA + Worker + local D1 + auth.
const PORT = Number(process.env.PLAYWRIGHT_PORT ?? 4189)
const baseURL = `http://localhost:${PORT}`
const externalPort = Number(process.env.E2E_EXTERNAL_PORT ?? 4399)
const externalOrigin = `http://127.0.0.1:${externalPort}`
const nativePort = Number(process.env.E2E_NATIVE_PORT ?? 4400)
const nativeOrigin = `http://127.0.0.1:${nativePort}`
const configuredPersistStatePath = process.env.CF_PERSIST_STATE_PATH
const persistStatePath = configuredPersistStatePath ?? mkdtempSync(join(tmpdir(), 'realmroot-e2e-'))
process.env.CF_PERSIST_STATE_PATH = persistStatePath
if (!configuredPersistStatePath) process.env.REALMROOT_E2E_TEMP_STATE_PATH = persistStatePath
export default defineConfig<RealmrootOptions>({
testDir: './e2e',
testMatch: '**/*.spec.ts',
fullyParallel: false,
workers: 1,
timeout: 60_000,
forbidOnly: !!process.env.CI,
retries: 0,
reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : 'list',
globalTeardown: './e2e/global-teardown.ts',
use: {
baseURL,
screenshot: 'only-on-failure',
trace: 'retain-on-failure',
},
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'], realmrootTarget: 'local' } }],
webServer: [
{
command: 'pnpm run example:resource-external',
url: `${externalOrigin}/.well-known/oauth-protected-resource/api`,
timeout: 30_000,
reuseExistingServer: !process.env.CI,
env: {
PORT: String(externalPort),
ORIGIN: externalOrigin,
},
},
{
command: 'pnpm run example:resource-native',
url: `${nativeOrigin}/api`,
timeout: 30_000,
reuseExistingServer: !process.env.CI,
env: {
PORT: String(nativePort),
ORIGIN: nativeOrigin,
REALMROOT_ORIGIN: baseURL,
},
},
{
command: `vite dev --host 127.0.0.1 --mode e2e --port ${PORT}`,
url: `${baseURL}/api/health`,
timeout: 120_000,
reuseExistingServer: !process.env.CI,
env: {
CF_WRANGLER_CONFIG: process.env.E2E_WRANGLER_CONFIG ?? 'e2e/wrangler.toml',
CF_PERSIST_STATE_PATH: persistStatePath,
PLAYWRIGHT_PORT: String(PORT),
},
},
],
})