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

/**
 * Playwright configuration for website smoke tests
 * 
 * Purpose: Verify all website pages load without runtime errors
 * Scope: Page rendering, console errors, React hydration
 * 
 * Critical Detection:
 * - Console errors during page load
 * - React hydration mismatches
 * - Navigation failures
 * - Missing content
 */
export default defineConfig({
  testDir: './tests/smoke',
  testMatch: ['**/website-pages.spec.ts'],
  testIgnore: ['**/electron-build.smoke.test.ts'],
  
  // Serial execution for consistent results
  fullyParallel: false,
  workers: 1,
  
  // Fail fast - stop on first error
  maxFailures: 1,
  
  // Timeout: Pages should load quickly
  timeout: 30_000,
  
  // Base URL for the website
  use: {
    baseURL: 'http://localhost:3000',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
    trace: 'retain-on-failure',
  },
  
  // Reporter: verbose for debugging
  reporter: [
    ['list'],
    ['html', { open: 'never' }]
  ],
  
  // No retry - smoke tests must pass on first run
  retries: 0,
  
  // Web server configuration
  webServer: {
    command: 'npm run dev -w @gridpilot/website',
    url: 'http://localhost:3000',
    timeout: 120_000,
    reuseExistingServer: !process.env.CI,
  },
  
  // Browser projects
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});