import { defineConfig, devices } from '@playwright/test';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const reportDir = path.resolve(__dirname, 'e2e-report');
const resultDir = path.resolve(__dirname, 'e2e-results');
const junitFile = path.resolve(__dirname, 'e2e-results.xml');

export default defineConfig({
  testDir: './tests',
  testMatch: '*.spec.ts',
  fullyParallel: false,
  workers: 1,
  retries: 0,
  reporter: [
    ['list'],
    ['html', { outputFolder: reportDir, open: 'never' }],
    ['junit', { outputFile: junitFile }]
  ],
  outputDir: resultDir,
  globalSetup: './global-setup.cjs',

  use: {
    baseURL: process.env.PLAYWRIGHT_BASE_URL || 'http://localhost:5176',
    trace: 'off',
    screenshot: 'off',
    video: 'off',
    actionTimeout: 30000,
    navigationTimeout: 60000,
  },

  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        launchOptions: {
          args: ['--no-sandbox', '--disable-setuid-sandbox']
        }
      },
    },
  ],
});
