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

// WebKit only — hard constraint: verify apps in Safari's rendering engine.
// Video + trace recorded for every test so a failed deploy has a replay.
const BASE_DOMAIN = process.env.BASE_DOMAIN ?? 'riotpiao.com';

// Set E2E_IGNORE_TLS=1 only during early bootstrap (staging certs). Default is
// strict so a broken TLS chain FAILS the suite — that is a real deploy failure.
const ignoreHTTPSErrors = process.env.E2E_IGNORE_TLS === '1';

export default defineConfig({
  testDir: './tests',
  outputDir: './test-results',
  // Serial + retries: this is a smoke gate, not a load test.
  fullyParallel: false,
  workers: 1,
  retries: process.env.CI ? 1 : 0,
  timeout: 60_000,
  expect: { timeout: 15_000 },

  reporter: [
    ['list'],
    ['html', { outputFolder: 'playwright-report', open: 'never' }],
    ['json', { outputFile: 'test-results/results.json' }],
  ],

  use: {
    baseURL: `https://${BASE_DOMAIN}`,
    ignoreHTTPSErrors,
    video: 'on',
    trace: 'on',
    screenshot: 'on',
    navigationTimeout: 30_000,
    actionTimeout: 15_000,
  },

  projects: [
    { name: 'webkit', use: { ...devices['Desktop Safari'] } },
  ],
});
