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

const baseURL = process.env.BASE_URL;

if (!baseURL || new URL(baseURL).protocol !== "https:") {
  throw new Error("BASE_URL must be an HTTPS origin for the PWA test");
}

export default defineConfig({
  testDir: "./pwa",
  outputDir: "./output/pwa-test-results",
  fullyParallel: false,
  workers: 1,
  forbidOnly: true,
  retries: 0,
  timeout: 90_000,
  expect: {
    timeout: 15_000,
  },
  reporter: [
    ["line"],
    ["html", { outputFolder: "./output/pwa-html-report", open: "never" }],
    ["json", { outputFile: "./output/pwa-results.json" }],
  ],
  use: {
    baseURL,
    ignoreHTTPSErrors: false,
    serviceWorkers: "allow",
    actionTimeout: 10_000,
    navigationTimeout: 20_000,
    trace: "retain-on-failure",
    screenshot: "only-on-failure",
    video: "retain-on-failure",
  },
  projects: [
    {
      name: "chromium-pwa",
      use: {
        ...devices["Desktop Chrome"],
      },
    },
  ],
});
