mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-12 20:03:03 +03:00
feat: support custom png comparator (#18689)
This way we might experiment with different custom PNG comparators for VRT.
This commit is contained in:
parent
e42583f477
commit
dfb4ad388a
@ -24,9 +24,19 @@ export type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: numbe
|
||||
export 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')
|
||||
|
Loading…
Reference in New Issue
Block a user