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

const useSystemEdge = process.env.PW_USE_SYSTEM_EDGE === '1'
const skipWebServer = process.env.PW_SKIP_WEB_SERVER === '1'

export default defineConfig({
  testDir: './tests/e2e',
  fullyParallel: true,
  retries: process.env.CI ? 2 : 0,
  reporter: process.env.CI ? 'github' : 'list',
  use: {
    baseURL: 'http://127.0.0.1:4173',
    trace: 'on-first-retry',
  },
  webServer: skipWebServer
    ? undefined
    : {
        command: 'pnpm preview --host 127.0.0.1 --port 4173',
        url: 'http://127.0.0.1:4173',
        reuseExistingServer: !process.env.CI,
        cwd: '.',
      },
  projects: [
    {
      name: useSystemEdge ? 'msedge' : 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        ...(useSystemEdge ? { channel: 'msedge' } : {}),
      },
    },
  ],
})
