// =============================================================================
// AgenciaPsi — Playwright config (T#10)
// =============================================================================
// E2E roda contra dev server local. Specs em e2e/, isoladas dos unit tests.
//
// Uso:
//   npm run test:e2e           — roda todos
//   npm run test:e2e:ui        — modo UI (debug)
//   npx playwright test e2e/patient-intake.spec.js
// =============================================================================
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
    testDir: './e2e',
    timeout: 30_000,
    expect: { timeout: 5_000 },
    fullyParallel: true,
    forbidOnly: !!process.env.CI,
    retries: process.env.CI ? 1 : 0,
    workers: process.env.CI ? 1 : undefined,
    reporter: [['list']],

    use: {
        baseURL: 'http://localhost:5173',
        trace: 'retain-on-failure',
        screenshot: 'only-on-failure'
    },

    projects: [
        {
            name: 'chromium',
            use: { ...devices['Desktop Chrome'] }
        }
    ],

    // Sobe o dev server automaticamente se ainda não estiver rodando
    webServer: {
        command: 'npm run dev',
        url: 'http://localhost:5173',
        reuseExistingServer: true,
        timeout: 120_000
    }
});
