import { defineConfig } from '@playwright/test'

// 通过环境变量 DEV_MODE 切换模式：
// - 默认（IIS模式）：直接连接已部署的 http://127.0.0.1/admin，不启动本地dev server
// - DEV_MODE=1：启动 npm run dev，连接 http://localhost:5173
const isDev = !!process.env.DEV_MODE

export default defineConfig({
  testDir: './e2e',
  timeout: 60000,
  expect: { timeout: 10000 },
  fullyParallel: false,
  retries: 0,
  use: {
    baseURL: isDev ? 'http://localhost:5173' : 'http://127.0.0.1/admin',
    headless: true,
    screenshot: 'only-on-failure',
    trace: 'retain-on-failure',
    actionTimeout: 10000,
  },
  projects: [
    { name: 'chromium', use: { browserName: 'chromium' } },
  ],
  // IIS模式下不启动webServer，直接连接已部署的站点
  ...(isDev ? {
    webServer: {
      command: 'npm run dev',
      port: 5173,
      reuseExistingServer: true,
      timeout: 30000,
    }
  } : {}),
})
