import { defineConfig, devices } from '@playwright/test'; import path from 'path'; /** * Landing 门禁专用 Playwright 配置(`npm run test:landing`)。 * * ## 为什么单独一份配置 * * landing 的四道门禁原本是 `novavis-authority` 仓里的四个 python 脚本 * (`verify-landing-layout` / `verify-landing-motion` / `landing-demo-verify` / * `landing-audit`),2026-12-03 随 landing 源码一起迁入本仓。它们**只在 chrome 单引擎、 * 单 project 下跑**,且每条用例自己 setViewportSize(视口是被测对象的一部分)。 * * 若塞进 `playwright.config.ts` 的 4 个功能 project(chromium / chromium-mobile / * firefox / webkit),同一套断言会在 4 个引擎 × 4 个视口下重复执行: * ① 判据里有多处「窄视口下 X 不可见」的断言,在 mobile project 的固定 390 视口下会被 * spec 自己的 setViewportSize 覆盖,跑 4 遍等于跑 1 遍却贵 4 倍; * ② webkit/firefox 上 `checkVisibility({checkVisibilityCSS})` 与 `:has()` 支持面不同, * 会把「引擎差异」混进「landing 是否合规」的读数里。 * * 所以用独立 config + 独立 project:**一个引擎、一份读数**,与迁移前的四道门禁口径一致。 * 主 config 完全不动(`test:functional` 显式传 --project,不会捡到本文件)。 * * ## webServer * * 与主 config 同源:默认 `npm run dev`;`E2E_TARGET=production` 时打 `dist/standalone/server.js`。 * landing 是 `public/` 下的静态文件 + 4 条 rewrite(`next.config.mjs`),dev 与产物都能服务。 */ export default defineConfig({ testDir: './landing', fullyParallel: false, // 门禁共享同一个 dev server 且会改视口/注入 CSS,串行才能保证读数可复现 forbidOnly: !!process.env.CI, retries: 0, workers: 1, reporter: [['list', { printSteps: true }]], outputDir: path.join(__dirname, 'test-results-landing'), use: { baseURL: process.env.E2E_BASE_URL || 'http://localhost:3000', trace: 'off', screenshot: 'only-on-failure', // 门禁自身会按需 setViewportSize,这里给一个与迁移前一致的初始视口 viewport: { width: 1440, height: 900 }, // landing 页无登录态:清空 storageState,避免把主站 cookie 带进来影响读数 storageState: { cookies: [], origins: [] }, ignoreHTTPSErrors: true, actionTimeout: 15000, navigationTimeout: 30000, }, expect: { timeout: 15000 }, projects: [ { name: 'landing', // 顺序有意义:`devices[...]` 自带 viewport 1280×720,必须**在展开之后**覆盖, // 否则 `use` 层写的 1440×900 会被 project 层盖掉(实测:hero 在 720 高视口下 // 落在首屏之外,IntersectionObserver 不触发,剧本采样到空序列而假失败)。 use: { ...devices['Desktop Chrome'], viewport: { width: 1440, height: 900 } }, }, ], webServer: { command: process.env.E2E_TARGET === 'production' ? 'HOSTNAME=localhost PORT=3000 node dist/standalone/server.js' : 'npm run dev', url: 'http://localhost:3000', reuseExistingServer: !process.env.CI && process.env.E2E_TARGET !== 'production', timeout: 180000, cwd: '..', env: { CMS_REVALIDATE_SECRET: process.env.CMS_REVALIDATE_SECRET || 'e2e-test-secret', }, }, });