import { defineConfig } from '@playwright/test' import { existsSync } from 'node:fs' /** * Playwright 配置 — baseline 0 视觉差验证基础设施。 * * - testDir: tests/e2e * - projects: setup (auth.setup.ts UI 登录一次) → chromium (复用 storageState) * - baseURL: 默认 http://nginx/ (容器内, fallback http://127.0.0.1:30000) * * 跑法: * npx playwright test --project=setup # 单独刷新登录态 * npx playwright test --project=chromium # 业务 spec (需先有 .auth/admin.json) * npx playwright test # 全部 (setup 自动作为 chromium 依赖运行) * * 注: storageState 只有在 .auth/admin.json 存在时才装载 (首跑前为 undefined, setup 会创建) */ const AUTH_FILE = '.auth/admin.json' export default defineConfig({ testDir: './tests/e2e', fullyParallel: false, workers: 1, retries: 0, timeout: 60_000, reporter: [['list']], use: { baseURL: process.env.JNPF_BASE_URL || 'http://nginx/', headless: true, screenshot: 'only-on-failure', trace: 'retain-on-failure', }, projects: [ { name: 'setup', testMatch: /.*\.setup\.ts/, }, { name: 'chromium', use: { browserName: 'chromium', ...(existsSync(AUTH_FILE) ? { storageState: AUTH_FILE } : {}), }, testIgnore: /.*\.setup\.ts/, dependencies: ['setup'], }, ], })