import { defineConfig, devices } from "@playwright/test";

const baseURL = process.env.BASE_URL;

if (!baseURL) {
  throw new Error("BASE_URL is required");
}

export default defineConfig({
  testDir: "./tests",
  outputDir: "./output/test-results",
  fullyParallel: false,
  workers: 1,
  forbidOnly: true,
  retries: 0,
  timeout: 90_000,
  expect: {
    timeout: 10_000,
  },
  reporter: [
    ["line"],
    ["html", { outputFolder: "./output/html-report", open: "never" }],
    ["json", { outputFile: "./output/results.json" }],
  ],
  use: {
    baseURL,
    ignoreHTTPSErrors: true,
    // The isolated E2E proxy uses a generated self-signed certificate. Browser
    // page requests honor ignoreHTTPSErrors, but Chromium's service-worker
    // fetch does not. Static delivery is covered by the backend suite.
    serviceWorkers: "block",
    actionTimeout: 10_000,
    navigationTimeout: 20_000,
    trace: "retain-on-failure",
    screenshot: "only-on-failure",
    video: "retain-on-failure",
  },
  projects: [
    {
      name: "chromium",
      use: {
        ...devices["Desktop Chrome"],
      },
    },
    {
      name: "firefox",
      use: {
        ...devices["Desktop Firefox"],
      },
    },
    {
      name: "webkit",
      use: {
        ...devices["Desktop Safari"],
      },
    },
  ],
});
