import { defineConfig, devices } from "@playwright/test"; // E2E_BUILD=1 时使用生产构建,避免按需编译导致超时 const useBuild = process.env.E2E_BUILD === "1"; export default defineConfig({ testDir: "./e2e/tests", // 本地开发启用并行,CI 环境串行 fullyParallel: !process.env.CI, forbidOnly: !!process.env.CI, // 本地 1 次重试,CI 2 次 retries: process.env.CI ? 2 : 1, // 本地 2 个 worker(避免机器卡顿),CI 1 个 workers: process.env.CI ? 1 : 2, reporter: "html", // 生产构建已预编译,超时可以缩短 timeout: useBuild ? 60 * 1000 : 120 * 1000, use: { baseURL: "http://localhost:3000", trace: "on-first-retry", screenshot: "only-on-failure", video: "retain-on-failure", actionTimeout: 30000, navigationTimeout: useBuild ? 15000 : 60000, }, projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"] }, }, { name: "firefox", use: { ...devices["Desktop Firefox"] }, }, { name: "webkit", use: { ...devices["Desktop Safari"] }, }, ], webServer: { // E2E_BUILD=1 时先 build 再 start,否则用 dev command: useBuild ? "npm run build && npm start" : "npm run dev", url: "http://localhost:3000/api/auth/session", reuseExistingServer: true, timeout: useBuild ? 300 * 1000 : 120 * 1000, maxRetries: 3, }, });