import { defineConfig, devices } from "@playwright/test"; const apiMode = process.env.VITE_API_MODE === "mock" ? "mock" : "server"; const webServerPort = apiMode === "mock" ? 8889 : 8888; const serverTestMatch = [ "**/server-mode-boundary.spec.ts", "**/smoke.spec.ts", "**/auth.spec.ts", "**/accessibility-shell.spec.ts", ] as const; const serverDomainTestMatch = [ "**/series.spec.ts", "**/fan-talk.spec.ts", "**/comments.spec.ts", ] as const; const mockTestMatch = ["**/mock-preview-shell.spec.ts", "**/mock-mode-boundary.spec.ts", "**/character-workspace.spec.ts", "**/audio-content.spec.ts", "**/series.spec.ts", "**/community.spec.ts", "**/fan-talk.spec.ts", "**/comments.spec.ts", "**/resource-workflows.spec.ts", "**/error-mapping.spec.ts", "**/responsive-capabilities.spec.ts", "**/accessibility.spec.ts"] as const; const serverDomainSpecNames = ["series.spec.ts", "fan-talk.spec.ts", "comments.spec.ts"] as const; const requestedServerDomainTestMatch = serverDomainTestMatch.filter((_, index) => process.argv.some((argument) => argument.endsWith(serverDomainSpecNames[index] ?? ""))); export default defineConfig({ testDir: "./tests/e2e", webServer: { command: apiMode === "mock" ? "npm run dev:mock" : "npm run dev", env: { VITE_API_MODE: apiMode }, url: `http://127.0.0.1:${webServerPort}`, reuseExistingServer: !process.env.CI, }, use: { baseURL: `http://127.0.0.1:${webServerPort}`, }, testMatch: apiMode === "mock" ? [...mockTestMatch] : [...serverTestMatch, ...requestedServerDomainTestMatch], timeout: apiMode === "mock" ? 60_000 : undefined, workers: apiMode === "mock" ? 1 : undefined, projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"] } }, { name: "mobile-chrome", use: { ...devices["Pixel 5"] } }, ], });