import { devices } from '@playwright/test'; import { env } from 'node:process'; import type { PlaywrightTestConfig } from '@playwright/test'; const BASE_URL = env.DEVSTAR_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000'; const config: PlaywrightTestConfig = { testDir: './specs', testMatch: /specs\/.*\.test\.ts/, timeout: 500000, expect: { timeout: 15000, }, forbidOnly: Boolean(env.CI), retries: env.CI ? 2 : 0, reporter: [['html', { outputFolder: 'playwright-report/html', open: 'never' }]], use: { headless: true, locale: 'zh-CN', timezoneId: 'Asia/Shanghai', actionTimeout: 15000, navigationTimeout: 15000, baseURL: BASE_URL, trace: 'on-first-retry', screenshot: 'only-on-failure', }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'], }, }, ], outputDir: 'playwright-report/test-artifacts/', snapshotDir: 'playwright-report/test-snapshots/', }; const skipInstall = env.E2E_SKIP_INSTALL === 'true'; if (skipInstall) { console.log(`已跳过 global-setup.`); } else { console.log(`[Playwright Config] 探测结果: E2E_SKIP_INSTALL is not 'true'. 已启用 global-setup.`); config.globalSetup = require.resolve('./global-setup.ts'); } export default config satisfies PlaywrightTestConfig;