import path from "node:path"; import { defineConfig, devices } from "@playwright/test"; import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs"; import { stageTwoOrigins } from "./e2e-2origin/globalSetup"; // Test-only environment (declared here, one-core Phase 4 slice 3): // E2E_TWO_ORIGIN_REBUILD=1 rebuild the cached hub bundle under .2origin // (e2e-2origin/globalSetup.ts); otherwise a staged // hubA/sw.js is reused. // The two ports are common/lib/ports.mjs's, offset per worktree. // Real two-origin test: proves what the route-mocked e2e-hub suite can't — // genuine cross-origin CORS enforcement and the prod service worker offline // path. We stage Origin B (CORS JSON) and Origin A (a real hub build) HERE at // config load — before the webServer array starts — because Playwright launches // webServers before globalSetup. The two webServer entries then serve the staged // dirs, and the hub reads Origin B over the network like a deployed hub would. const STAGE = path.resolve(process.cwd(), ".2origin"); const B_PORT = portFor("ORIGIN_B_PORT"); const A_PORT = portFor("HUB_A_PORT"); const baseURL = `http://localhost:${A_PORT}`; // Stage once, in the runner. Playwright evaluates this config again in every // worker process (it sets TEST_WORKER_INDEX there before loading it), and a // re-stage deletes and rewrites originB under the `serve` already serving it. if (!process.env.TEST_WORKER_INDEX) stageTwoOrigins(); export default defineConfig({ testDir: "./e2e-2origin", timeout: 60_000, retries: process.env.CI ? 2 : 0, // `json` beside `list`: the run's timing record, which // scripts/e2e-timings.mjs totals per spec against the branch's last run. reporter: process.env.CI ? "github" : [["list"], ["json", { outputFile: "test-results-2origin/timings.json" }]], outputDir: "test-results-2origin/", fullyParallel: false, workers: 1, webServer: [ { command: `pnpm exec serve ${path.join(STAGE, "originB")} -l ${B_PORT} --no-request-logging`, url: `http://localhost:${B_PORT}/site.json`, timeout: 60_000, reuseExistingServer: !process.env.CI, }, { command: `pnpm exec serve ${path.join(STAGE, "hubA")} -l ${A_PORT} --no-request-logging`, url: `${baseURL}/`, timeout: 60_000, reuseExistingServer: !process.env.CI, }, ], use: { baseURL, trace: "on-first-retry", screenshot: "only-on-failure", video: "retain-on-failure", }, projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"], viewport: { width: 1440, height: 1200 } }, }, ], });