d0ef462921
验证:713 项单测、8 视口环境、代码及格式检查通过;未运行生产构建。
76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
/*
|
||
Copyright (C) 2025 QuantumNous
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Affero General Public License as
|
||
published by the Free Software Foundation, either version 3 of the
|
||
License, or (at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Affero General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Affero General Public License
|
||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
For commercial licensing, please contact support@quantumnous.com
|
||
*/
|
||
|
||
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 };
|
||
}
|
||
}
|