cb9d836227
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
94 lines
2.8 KiB
JavaScript
94 lines
2.8 KiB
JavaScript
import { defineConfig } from '@playwright/test';
|
|
import {
|
|
browserChannel,
|
|
contextOptions,
|
|
projectViewports,
|
|
} from './scripts/browser-environment.mjs';
|
|
import { runtimeOptions } from './scripts/playwright-runtime.mjs';
|
|
import { findDevService } from './scripts/dev-service.mjs';
|
|
|
|
if (
|
|
!process.argv.includes('--list') &&
|
|
!process.env.PW_TARGET &&
|
|
!process.env.PW_BASE_URL
|
|
) {
|
|
const existing = await findDevService();
|
|
if (existing) {
|
|
process.env.PW_TARGET = 'remote';
|
|
process.env.PW_BASE_URL = existing;
|
|
}
|
|
}
|
|
|
|
const runtime = runtimeOptions({ defaultPort: 4176, defaultWorkers: 1 });
|
|
const { target, baseURL, isCI, headless, workers, outputDir, reportDir } =
|
|
runtime;
|
|
if (
|
|
isCI &&
|
|
process.argv.some((argument) =>
|
|
['--headed', '--debug', '--ui'].includes(argument),
|
|
)
|
|
)
|
|
throw new Error('CI requires headless non-interactive tests');
|
|
const viewports = runtime.extended
|
|
? projectViewports
|
|
: projectViewports.slice(0, 2);
|
|
|
|
// UI_VISUAL_OFFSCREEN=0 仅限人工本地可视化调试时临时使用。
|
|
// Agent、CI、无头/自动化环境禁止设置该值,必须保持默认离屏模式
|
|
// (或 UI_VISUAL_OFFSCREEN=1),避免弹出 UI 或依赖显示环境。
|
|
// 离屏不能保证系统启动时不激活窗口;公共 fixture 探测到前台或状态不明时停止。
|
|
const listOnly = process.argv.includes('--list');
|
|
|
|
export default defineConfig({
|
|
testDir: './e2e',
|
|
testMatch: '**/*.spec.js',
|
|
outputDir,
|
|
fullyParallel: false,
|
|
workers,
|
|
forbidOnly: isCI || runtime.requireAll,
|
|
failOnFlakyTests: isCI,
|
|
retries: isCI ? 1 : 0,
|
|
timeout: 30000,
|
|
expect: { timeout: 5000 },
|
|
reporter: listOnly
|
|
? [['list']]
|
|
: [
|
|
['list'],
|
|
['html', { outputFolder: reportDir, open: 'never' }],
|
|
...(isCI ? [['junit', { outputFile: `${outputDir}/junit.xml` }]] : []),
|
|
['./scripts/playwright-reporter.mjs'],
|
|
],
|
|
metadata: {
|
|
platform: process.platform,
|
|
node: process.version,
|
|
target,
|
|
baseURL: baseURL.href,
|
|
runId: runtime.runId,
|
|
},
|
|
use: {
|
|
baseURL: baseURL.href,
|
|
headless,
|
|
launchOptions: { args: runtime.launchArgs },
|
|
...contextOptions('desktop'),
|
|
screenshot: { mode: 'only-on-failure', scale: 'css' },
|
|
trace: 'retain-on-failure',
|
|
video: runtime.video ? 'retain-on-failure' : 'off',
|
|
},
|
|
projects: viewports.map((name) => ({
|
|
name: `chrome-${name}`,
|
|
use: { ...contextOptions(name), channel: browserChannel },
|
|
})),
|
|
webServer:
|
|
target === 'remote'
|
|
? undefined
|
|
: {
|
|
command:
|
|
target === 'local-dist'
|
|
? `node scripts/preview-dist.mjs --port ${baseURL.port || 80}`
|
|
: `npm run dev -- --host 127.0.0.1 --port ${baseURL.port || 80} --strictPort`,
|
|
url: baseURL.href,
|
|
reuseExistingServer: false,
|
|
timeout: 30000,
|
|
},
|
|
});
|