Reuse annotation var
This commit is contained in:
@@ -19,6 +19,8 @@ import {
|
|||||||
import { sanitizeForFilePath } from "playwright-core/lib/utils";
|
import { sanitizeForFilePath } from "playwright-core/lib/utils";
|
||||||
import { extname } from "node:path";
|
import { extname } from "node:path";
|
||||||
|
|
||||||
|
import { ANNOTATION } from "../stale-screenshot-reporter.js";
|
||||||
|
|
||||||
// Based on https://github.com/microsoft/playwright/blob/2b77ed4d7aafa85a600caa0b0d101b72c8437eeb/packages/playwright/src/util.ts#L206C8-L210C2
|
// Based on https://github.com/microsoft/playwright/blob/2b77ed4d7aafa85a600caa0b0d101b72c8437eeb/packages/playwright/src/util.ts#L206C8-L210C2
|
||||||
function sanitizeFilePathBeforeExtension(filePath: string): string {
|
function sanitizeFilePathBeforeExtension(filePath: string): string {
|
||||||
const ext = extname(filePath);
|
const ext = extname(filePath);
|
||||||
@@ -68,8 +70,7 @@ export const expect = baseExpect.extend<Expectations>({
|
|||||||
await style?.evaluate((tag) => tag.remove());
|
await style?.evaluate((tag) => tag.remove());
|
||||||
|
|
||||||
testInfo.annotations.push({
|
testInfo.annotations.push({
|
||||||
// `_` prefix hides it from the HTML reporter
|
type: ANNOTATION,
|
||||||
type: "_screenshot",
|
|
||||||
description: testInfo.snapshotPath(screenshotName),
|
description: testInfo.snapshotPath(screenshotName),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ import path from "node:path";
|
|||||||
import { type Reporter, type TestCase } from "@playwright/test/reporter";
|
import { type Reporter, type TestCase } from "@playwright/test/reporter";
|
||||||
import { type FullConfig } from "@playwright/test";
|
import { type FullConfig } from "@playwright/test";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The annotation type used to mark screenshots in tests.
|
||||||
|
* `_` prefix hides it from the HTML reporter
|
||||||
|
*/
|
||||||
|
export const ANNOTATION = "_screenshot";
|
||||||
|
|
||||||
class StaleScreenshotReporter implements Reporter {
|
class StaleScreenshotReporter implements Reporter {
|
||||||
private readonly snapshotRoots = new Set<string>();
|
private readonly snapshotRoots = new Set<string>();
|
||||||
private readonly screenshots = new Set<string>();
|
private readonly screenshots = new Set<string>();
|
||||||
@@ -34,7 +40,7 @@ class StaleScreenshotReporter implements Reporter {
|
|||||||
this.failing = true;
|
this.failing = true;
|
||||||
}
|
}
|
||||||
for (const annotation of test.annotations) {
|
for (const annotation of test.annotations) {
|
||||||
if (annotation.type === "_screenshot" && annotation.description) {
|
if (annotation.type === ANNOTATION && annotation.description) {
|
||||||
this.screenshots.add(annotation.description);
|
this.screenshots.add(annotation.description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user