From 75cf1ee738d44e86d8bdcce8b136e6cae62de611 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 20 Jun 2025 10:28:04 +0100 Subject: [PATCH] Reuse annotation var --- .../src/expect/screenshot.ts | 5 +++-- .../src/stale-screenshot-reporter.ts | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/element-web-playwright-common/src/expect/screenshot.ts b/packages/element-web-playwright-common/src/expect/screenshot.ts index 6a4fadf0dc..86687b28e4 100644 --- a/packages/element-web-playwright-common/src/expect/screenshot.ts +++ b/packages/element-web-playwright-common/src/expect/screenshot.ts @@ -19,6 +19,8 @@ import { import { sanitizeForFilePath } from "playwright-core/lib/utils"; 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 function sanitizeFilePathBeforeExtension(filePath: string): string { const ext = extname(filePath); @@ -68,8 +70,7 @@ export const expect = baseExpect.extend({ await style?.evaluate((tag) => tag.remove()); testInfo.annotations.push({ - // `_` prefix hides it from the HTML reporter - type: "_screenshot", + type: ANNOTATION, description: testInfo.snapshotPath(screenshotName), }); diff --git a/packages/element-web-playwright-common/src/stale-screenshot-reporter.ts b/packages/element-web-playwright-common/src/stale-screenshot-reporter.ts index 3814daa322..f2e0d39de7 100644 --- a/packages/element-web-playwright-common/src/stale-screenshot-reporter.ts +++ b/packages/element-web-playwright-common/src/stale-screenshot-reporter.ts @@ -16,6 +16,12 @@ import path from "node:path"; import { type Reporter, type TestCase } from "@playwright/test/reporter"; 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 { private readonly snapshotRoots = new Set(); private readonly screenshots = new Set(); @@ -34,7 +40,7 @@ class StaleScreenshotReporter implements Reporter { this.failing = true; } for (const annotation of test.annotations) { - if (annotation.type === "_screenshot" && annotation.description) { + if (annotation.type === ANNOTATION && annotation.description) { this.screenshots.add(annotation.description); } }