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

/**
 * Playwright config for Africa Alert E2E tests.
 *
 * Assumes both servers are already running:
 *   - Server  on http://localhost:3001  (`cd server && npm run dev`)
 *   - Client  on http://localhost:3000  (`cd client && npm run dev`)
 *
 * The client Vite dev server proxies `/api/*` to :3001, so all tests
 * can navigate to `http://localhost:3000` and the auth/contacts/etc.
 * calls still hit the API on 3001.
 *
 * To run the server + client first:
 *   cd server && npm run dev      # in one terminal
 *   cd client && npm run dev      # in another terminal
 * Then in a third terminal:
 *   cd client && npm run test:e2e
 */
export default defineConfig({
  testDir: './e2e',
  testMatch: '**/*.spec.ts',
  fullyParallel: false,        // single-process to avoid port-pinning races
  workers: 1,
  retries: 0,
  reporter: [['list']],
  timeout: 30_000,
  expect: { timeout: 10_000 },
  use: {
    baseURL: 'http://localhost:3000',
    headless: true,
    trace: 'retain-on-failure',
    screenshot: 'only-on-failure',
    viewport: { width: 1280, height: 800 },
    // Demo accounts are seeded by server/src/database/init.js
    // (admin/teacher/student/parent/...). See AGENTS.md.
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});
