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

/**
 * Playwright e2e config.
 * BASE_URL defaults to the shared Replit proxy (port 80) where both the
 * dashboard SPA and /api live.
 */
export default defineConfig({
  testDir: "./e2e",
  timeout: 60_000,
  expect: { timeout: 15_000 },
  fullyParallel: false,
  retries: 1,
  reporter: [
    ["list"],
    ["html", { open: "never", outputFolder: "playwright-report" }],
  ],

  use: {
    baseURL: process.env.BASE_URL ?? "http://localhost:80",
    headless: true,
    viewport: { width: 1280, height: 800 },
    // Sessions are cookie-based; ignore HTTPS errors in dev
    ignoreHTTPSErrors: true,
    trace: "on-first-retry",
    screenshot: "only-on-failure",
  },

  projects: [
    {
      name: "chromium",
      use: {
        ...devices["Desktop Chrome"],
        // Use the Nix-installed system Chromium; the downloaded headless-shell
        // binary is missing shared libraries in this NixOS environment.
        launchOptions: {
          executablePath:
            process.env.CHROMIUM_PATH ??
            "/nix/store/qa9cnw4v5xkxyip6mb9kxqfq1z4x2dx1-chromium-138.0.7204.100/bin/chromium",
          args: ["--no-sandbox", "--disable-dev-shm-usage"],
        },
      },
    },
  ],
});
