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

/**
 * Playwright discovers specs in any `__tests__/e2e/` folder under `src/` (onboarding, lifecycle, etc.).
 *
 * Starts Vite automatically unless CI sets PLAYWRIGHT_SKIP_WEB_SERVER=1
 * (useful when the dev server is already running).
 */
export default defineConfig({
    testDir: "./src",
    testMatch: "**/__tests__/e2e/**/*.e2e.spec.ts",
    fullyParallel: true,
    forbidOnly: !!process.env.CI,
    retries: process.env.CI ? 2 : 0,
    workers: process.env.CI ? 1 : undefined,
    reporter: process.env.CI ? "github" : "list",
    timeout: 60_000,
    expect: { timeout: 15_000 },
    use: {
        baseURL: process.env.PLAYWRIGHT_BASE_URL ?? "http://127.0.0.1:5173",
        trace: "on-first-retry",
        screenshot: "only-on-failure",
        video: "retain-on-failure",
    },
    projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
    webServer: process.env.PLAYWRIGHT_SKIP_WEB_SERVER
        ? undefined
        : {
              command: "npm run dev -- --host 127.0.0.1 --port 5173",
              url: "http://127.0.0.1:5173",
              reuseExistingServer: !process.env.CI,
              timeout: 120_000,
          },
});
