Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat: support custom png comparator (#18689)
Andrey Lushnikovdfb4ad388ae7
diff --git a/packages/playwright-core/src/utils/comparators.ts b/packages/playwright-core/src/utils/comparators.tsindex 43140c2da2..029764bbe9 100644--- a/packages/playwright-core/src/utils/comparators.ts+++ b/packages/playwright-core/src/utils/comparators.ts@@ -24,9 +24,19 @@ export type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: numbeexport type ComparatorResult = { diff?: Buffer; errorMessage: string; } | null;export type Comparator = (actualBuffer: Buffer | string, expectedBuffer: Buffer, options?: any) => ComparatorResult;+let customPNGComparator: Comparator | undefined;+if (process.env.PW_CUSTOM_PNG_COMPARATOR) {+ try {+ customPNGComparator = require(process.env.PW_CUSTOM_PNG_COMPARATOR);+ if (typeof customPNGComparator !== 'function')+ customPNGComparator = undefined;+ } catch (e) {+ }+}+export function getComparator(mimeType: string): Comparator {if (mimeType === 'image/png')- return compareImages.bind(null, 'image/png');+ return customPNGComparator ?? compareImages.bind(null, 'image/png');if (mimeType === 'image/jpeg')return compareImages.bind(null, 'image/jpeg');if (mimeType === 'text/plain')