Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test(this.urlPath_, async () => {
// Get the golden file path from the golden hash
const goldenHash = await this.getGoldenHash_();
const goldenPath = this.getImagePath_(goldenHash, 'golden');
if (!goldenPath) {
console.error('no goldenPath found');
return;
}
// Take a snapshot and download the golden image
const [snapshot, golden] = await Promise.all([
this.takeScreenshot_(),
this.readImage_(goldenPath),
]);
// Compare the images
const data = await compareImages(snapshot, golden, comparisonOptions);
const diff = data.getBuffer();
// Use the same hash for the snapshot path and diff path so it's easy can associate the two
const snapshotHash = this.generateImageHash_(snapshot);
const snapshotPath = this.getImagePath_(snapshotHash, 'snapshot');
const diffPath = this.getImagePath_(snapshotHash, 'diff');
const metadata: Storage.CustomFileMetadata = {golden: goldenHash};
if (!snapshotPath) {
console.error('no snapshotPath found');
return;
}
if (!diffPath) {
console.error('no diffPath found');
return;
}
// Save the snapshot and the diff
if (storage) {
left: number,
right: number,
bottom: number,
},
dimensionDifference: {
height: number,
width: number,
},
isSameDimensions: boolean,
misMatchPercentage: string,
error: void | string,
|}> {
const img1 = readFileSync(imgPath1)
const img2 = readFileSync(imgPath2)
return compareImages(img1, img2, {
output: {
errorColor: {
red: 255,
green: 0,
blue: 255,
},
errorType: 'movement',
transparency: 0.3,
largeImageThreshold: 1200,
useCrossOrigin: false,
outputDiff: true,
},
scaleToSameSize: true,
ignore: 'antialiasing',
})
}