2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
const FOCUS_ANNOTATION = 'focus-guard';
|
||
|
||
export default class AcceptanceReporter {
|
||
onBegin(config, suite) {
|
||
this.suite = suite;
|
||
this.focusEvents = new Set();
|
||
this.focusChecks = new Set();
|
||
this.headed = config.projects.some(
|
||
(project) => project.use?.headless === false,
|
||
);
|
||
}
|
||
|
||
onTestEnd(test, result) {
|
||
for (const note of [...(result.annotations || []), ...test.annotations]) {
|
||
if (note.type === FOCUS_ANNOTATION)
|
||
this.focusEvents.add(
|
||
`${test.titlePath().slice(1).join(' > ')}:${note.description}`,
|
||
);
|
||
if (note.type === 'focus-guard-checked')
|
||
this.focusChecks.add(`${test.id}:${note.description}`);
|
||
}
|
||
}
|
||
|
||
onEnd(result) {
|
||
// 焦点守护汇总:有事件时如实列出,不能宣称已保证后台运行
|
||
if (this.focusEvents.size) {
|
||
console.warn(
|
||
`\n[focus-guard] 记录到 ${this.focusEvents.size} 条焦点事件,本次运行不能宣称已保证后台运行:`,
|
||
);
|
||
for (const entry of this.focusEvents) console.warn(`- ${entry}`);
|
||
} else if (this.headed && this.focusChecks.size) {
|
||
console.log(
|
||
'\n[focus-guard] 各采样点(页面创建后、用例结束后)未检测到 Playwright Chrome 处于前台;采样点之间的瞬时激活无法排除',
|
||
);
|
||
}
|
||
if (process.env.PW_REQUIRE_ALL !== '1') return;
|
||
const incomplete = this.suite
|
||
.allTests()
|
||
.filter(
|
||
(test) =>
|
||
test.expectedStatus !== 'passed' ||
|
||
test.results.length === 0 ||
|
||
test.results.some((run) => run.status === 'skipped') ||
|
||
test.outcome() === 'flaky',
|
||
);
|
||
if (incomplete.length) {
|
||
console.error(
|
||
'Full acceptance requires every test to pass without skips, expected failures or flaky retries:',
|
||
);
|
||
for (const test of incomplete)
|
||
console.error(`- ${test.titlePath().join(' > ')}`);
|
||
return { status: 'failed' };
|
||
}
|
||
return { status: result.status };
|
||
}
|
||
}
|