import { defineConfig, devices } from '@playwright/test' // E2E config — drives a real Laravel test server. Used by `pnpm test:e2e`. // Component tests live in playwright-ct.config.ts (different runner). // // Architecture (B4 / TEST-CONTRACT-001): // - globalSetup runs `php artisan migrate:fresh --force --seed` against // crewli_test (the existing PHPUnit MySQL test DB) using the // E2EBaselineSeeder. Writes seeded IDs to api/storage/app/e2e-fixtures.json. // - webServer auto-starts `php artisan serve --port=8001` against the // same DB so the test can hit a live HTTP endpoint. // - Tests use page.context().request to call /api/v1/* with cookie auth // established via /api/v1/auth/login (Bearer-via-cookie, not stateful // Sanctum SPA flow — see api/.../SetAuthCookie.php). // // SCOPE: contract tests only (request shape verification). UI-driven e2e // tests would additionally need the Vite dev server (port 5174). Add that // to webServer when first UI-driven e2e test lands. // // CI integration: deferred to TEST-INFRA-002. This config currently // targets local-machine execution. const E2E_API_PORT = Number(process.env.E2E_API_PORT ?? 8001) // Use `localhost` (not 127.0.0.1) so the auth cookie set with // `domain=localhost` (per api/.env's SESSION_DOMAIN) is matched on // subsequent requests. Playwright's APIRequestContext respects // cookie scope strictly. const E2E_API_URL = `http://localhost:${E2E_API_PORT}` export default defineConfig({ testDir: './tests/playwright-e2e', fullyParallel: false, forbidOnly: !!process.env.CI, retries: 0, workers: 1, reporter: process.env.CI ? 'github' : 'list', globalSetup: './tests/playwright-e2e/global-setup.ts', use: { baseURL: E2E_API_URL, trace: 'off', video: 'off', screenshot: 'off', viewport: { width: 1440, height: 900 }, extraHTTPHeaders: { Accept: 'application/json', }, }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] }, }, ], // Auto-start the Laravel test server. globalSetup runs first // (migrate:fresh + seed), then this command spawns artisan serve // against the now-seeded crewli_test DB. webServer: { command: 'cd ../../api && DB_DATABASE=crewli_test php artisan --env=testing serve --port=8001', url: `${E2E_API_URL}/up`, reuseExistingServer: !process.env.CI, timeout: 60_000, stdout: 'ignore', stderr: 'pipe', }, })