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) {
baselines.forEach((baseline, idx) => {
resemble(baseline)
.compareTo(image)
.ignoreAntialiasing()
.onComplete((data) => {
if (minDelta >= data.misMatchPercentage) {
minDelta = data.misMatchPercentage;
minDiff = data.getImageDataUrl();
}
isSameDimensions = isSameDimensions || data.isSameDimensions;
if (idx + 1 === nbBaselines) {
done();
}
});
});
}
if (minDelta >= threshold) {
tapeContext.fail(
`<img src="${image}"> vs <img src="${
baselines[0]
}"> === <img src="${minDiff}">`
);
}
if (nextCallback) {
nextCallback();
} else {
tapeContext.end();
}
}
resemble.outputSettings({
transparency: 0.5,
});
baselines.forEach((baseline, idx) => {
resemble(baseline)
.compareTo(image)
.ignoreAntialiasing()
.onComplete((data) => {
if (minDelta >= data.misMatchPercentage) {
minDelta = data.misMatchPercentage;
minDiff = data.getImageDataUrl();
}
isSameDimensions = isSameDimensions || data.isSameDimensions;
if (idx + 1 === nbBaselines) {
done();
}
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',
})
}
module.exports = function() {
if (typeof window === "undefined") {
global.window = overrideWindow()
}
if (typeof FileReader === "undefined") {
global.FileReader = overrideFileReader()
}
if (typeof Image === "undefined") {
global.Image = overrideImage()
}
const resemblejs = require('resemblejs');
return resemblejs.apply(this, arguments);
};