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

/**
 * Playwright configuration for fully containerized e2e testing
 *
 * Purpose: Verify all website pages load without runtime errors
 * Scope: Page rendering, console errors, React hydration, API integration
 *
 * Critical Detection:
 * - Console errors during page load
 * - React hydration mismatches
 * - Navigation failures
 * - Missing content
 * - API connectivity issues
 *
 * Architecture: Everything runs in Docker
 * - Website: containerized Next.js (port 3100)
 * - API: containerized NestJS (port 3101)
 * - Database: containerized PostgreSQL (port 5434)
 * - Playwright: containerized test runner
 */

export default defineConfig({
  testDir: './tests',
  testMatch: process.env.RUN_EXHAUSTIVE_E2E === '1' 
    ? ['**/e2e/website/*.e2e.test.ts', '**/nightly/website/*.e2e.test.ts']
    : ['**/e2e/website/*.e2e.test.ts'],
  testIgnore: ['**/electron-build.smoke.test.ts'],
  
  // Serial execution for consistent results
  fullyParallel: false,
  workers: 1,
  
  // Continue on errors to see all failures
  maxFailures: undefined,
  
  // Timeout: Pages should load quickly
  timeout: 30_000,
  
  // Base URL for the website (containerized)
  use: {
    baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://website:3000',
    screenshot: 'off',
    video: 'off',
    trace: 'off',
  },
  
  // Reporter: verbose for debugging
  reporter: [
    ['list'],
    ['html', { open: 'never' }]
  ],
  
  // No retry - e2e tests must pass on first run
  retries: 0,
  
  // No webServer - everything runs in Docker
  webServer: undefined,
  
  // Browser projects
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});