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

const baseURL = 'http://localhost:3002';

export default defineConfig({
  testDir: './e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: 0,
  workers: 1,
  reporter: 'list',

  timeout: 30000,
  expect: {
    timeout: 10000,
  },

  use: {
    baseURL: baseURL,
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'off',
    actionTimeout: 10000,
    navigationTimeout: 15000,
    headless: true,
    locale: 'zh-CN',
    timezoneId: 'Asia/Shanghai',
    ignoreHTTPSErrors: true,
    bypassCSP: true,
    viewport: { width: 1280, height: 720 },
  },

  projects: [
    {
      name: 'ui-test',
      testMatch: '**/basic-ui-test.spec.ts',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'smoke-test',
      testMatch: '**/smoke/**/*.spec.ts',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'journey-test',
      testMatch: '**/journeys/**/*.spec.ts',
      use: { ...devices['Desktop Chrome'] },
    },
  ],

  webServer: {
    command: 'pnpm run dev',
    url: baseURL,
    reuseExistingServer: !process.env.CI,
    timeout: 120000,
  },
});