import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { defineConfig, devices } from "@playwright/test"; import type { CodemationPlaywrightPreparedEnvironment } from "./test/playwright/scripts/CodemationPlaywrightEnvironmentPreparer"; const hostPackageRoot = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(hostPackageRoot, "..", ".."); const preparedPath = path.join(hostPackageRoot, "test/playwright/.e2e-prepared.json"); if (!fs.existsSync(preparedPath)) { throw new Error( `Missing ${preparedPath}. Run pnpm run test:browser from @codemation/host (or pnpm exec tsx test/playwright/scripts/run-browser-e2e.ts).`, ); } const prepared = JSON.parse(fs.readFileSync(preparedPath, "utf8")) as CodemationPlaywrightPreparedEnvironment; const webServerEnv: Record = Object.fromEntries( Object.entries({ ...process.env, ...prepared.serverEnv, }).filter((entry): entry is [string, string] => typeof entry[1] === "string"), ); const baseUrl = String(prepared.serverEnv.AUTH_URL ?? "http://localhost:3001"); export default defineConfig({ timeout: 120_000, testDir: path.join(hostPackageRoot, "test/playwright/specs"), globalTeardown: path.join(hostPackageRoot, "test/playwright/global-teardown.ts"), forbidOnly: Boolean(process.env.CI), retries: process.env.CI ? 1 : 0, reporter: [ ["list"], [ "monocart-reporter", { name: "Codemation browser", outputFile: path.join(repoRoot, "coverage/raw/browser/monocart-report.html"), coverage: { outputDir: path.join(repoRoot, "coverage/raw/browser"), lcov: true, sourceFilter: (sourcePath: string) => sourcePath.includes("packages/next-host/src") || sourcePath.includes("packages/host/src"), }, }, ], ], use: { baseURL: baseUrl, trace: "retain-on-failure", video: "off", }, projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"], channel: "chrome" }, }, ], webServer: { command: "pnpm run e2e:serve-web", cwd: repoRoot, env: webServerEnv, url: baseUrl, reuseExistingServer: false, timeout: 180_000, stdout: "pipe", stderr: "pipe", }, });