const { defineConfig, devices } = require('@playwright/test');
const path = require('node:path');

const evidenceDir = process.env.E2E_EVIDENCE_DIR
  ? path.resolve(process.env.E2E_EVIDENCE_DIR)
  : path.resolve(__dirname, '../evidence/run-unknown');

const chromiumPath = process.env.PLAYWRIGHT_CHROMIUM_PATH
  || '/home/long/.cache/ms-playwright/chromium-1200/chrome-linux64/chrome';

module.exports = defineConfig({
  testDir: './e2e-admin/tests',
  testMatch: ['**/*.spec.ts'],
  fullyParallel: false,
  workers: 1,
  retries: 0,
  timeout: 5 * 60 * 1000,
  globalTimeout: 45 * 60 * 1000,
  maxFailures: 1,
  reporter: [
    ['list'],
    ['junit', { outputFile: path.join(evidenceDir, 'reports/junit.xml') }]
  ],
  reportSlowTests: { max: 10, threshold: 30000 },
  outputDir: path.join(evidenceDir, 'e2e'),
  use: {
    baseURL: process.env.E2E_BASE_URL || 'http://127.0.0.1:5174',
    trace: 'on',
    screenshot: 'only-on-failure',
    video: 'on',
    actionTimeout: 15000,
    navigationTimeout: 30000,
    viewport: { width: 1280, height: 720 },
    ignoreHTTPSErrors: true,
  },
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        launchOptions: {
          executablePath: chromiumPath,
          args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu']
        }
      },
    },
  ],
});
