feat: support custom png comparator (#18689)

This way we might experiment with different custom PNG comparators
for VRT.
This commit is contained in:
Andrey Lushnikov 2022-11-10 16:16:05 -08:00 committed by GitHub
parent e42583f477
commit dfb4ad388a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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')