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

/**
 * Playwright config for running e2e tests against the Angular app only.
 * Angular runs on port 4203 with NODE_OPTIONS=--openssl-legacy-provider.
 */
export default defineConfig({
  testDir: './tests/e2e-angular',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: [['html', { outputFolder: 'playwright-report-angular' }]],
  outputDir: 'test-results-angular',
  timeout: 45_000,
  use: {
    trace: 'on-first-retry',
    navigationTimeout: 15_000,
  },
  expect: {
    timeout: 15_000,
    toHaveScreenshot: {
      maxDiffPixelRatio: 0.05,
    },
  },
  projects: [
    {
      name: 'angular-ru-ru',
      use: {
        ...devices['Desktop Chrome'],
        baseURL: 'http://localhost:4203',
        locale: 'ru-ru',
      },
    },
  ],
  webServer: {
    command: 'cd ClientApp && NODE_OPTIONS=--openssl-legacy-provider npx ng serve --port 4203',
    url: 'http://localhost:4203',
    reuseExistingServer: true,
    timeout: 120_000,
  },
});
