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

/**
 * Every project boots its own copy of `.next/standalone` on an ephemeral port
 * with a local fake SMTP server behind it (see `tests/helpers/harness.ts`), so
 * the suite needs no long-lived dev server and no external mail credentials.
 *
 * Run `npm run build:standalone` first — `npm test` does it via `pretest`.
 */
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? "/clearfintest";

export { BASE_PATH };

export default defineConfig({
  testDir: "./tests",
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 1 : 0,
  workers: 1,
  reporter: process.env.CI ? "github" : "list",
  use: {
    trace: "on-first-retry",
  },
  projects: [
    {
      // Pure functions: config parsing, validation, escaping. No server, no I/O.
      name: "unit",
      testDir: "./tests/unit",
    },
    {
      // The HTTP API against the real bundle and a real (local) SMTP server.
      name: "api",
      testDir: "./tests/api",
    },
    {
      // Config delivered the way the deployed server receives it.
      name: "deploy",
      testDir: "./tests/deploy",
    },
    {
      name: "e2e",
      testDir: "./tests/e2e",
      use: { ...devices["Desktop Chrome"] },
    },
  ],
});
