Fix stale-screenshot-reporter.ts

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2025-01-10 11:37:20 +00:00
parent 1b8f62abe2
commit b203e4b2a5

View File

@@ -20,10 +20,13 @@ const snapshotRoot = path.join(__dirname, "snapshots");
class StaleScreenshotReporter implements Reporter { class StaleScreenshotReporter implements Reporter {
private screenshots = new Set<string>(); private screenshots = new Set<string>();
private failing = false;
private success = true; private success = true;
public onTestEnd(test: TestCase): void { public onTestEnd(test: TestCase): void {
if (!test.ok()) return; if (!test.ok()) {
this.failing = true;
}
for (const annotation of test.annotations) { for (const annotation of test.annotations) {
if (annotation.type === "_screenshot") { if (annotation.type === "_screenshot") {
this.screenshots.add(annotation.description); this.screenshots.add(annotation.description);
@@ -40,6 +43,8 @@ class StaleScreenshotReporter implements Reporter {
} }
public async onExit(): Promise<void> { public async onExit(): Promise<void> {
if (this.failing) return;
const screenshotFiles = new Set(await glob(`**/*.png`, { cwd: snapshotRoot })); const screenshotFiles = new Set(await glob(`**/*.png`, { cwd: snapshotRoot }));
for (const screenshot of screenshotFiles) { for (const screenshot of screenshotFiles) {
if (screenshot.split("-").at(-1) !== "linux.png") { if (screenshot.split("-").at(-1) !== "linux.png") {