Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compareNext()
return
}
const newPath = `screenshots/${commitRange[1]}/${filename}`
if (!fs.existsSync(newPath)) {
results[diffPath] = DIFF_REMOVED
compareNext()
return
}
const compareOptions = {
tolerance: 1e-6, // leave a little wiggle room for antialiasing inconsistencies
file: diffPath,
}
gm.compare(oldPath, newPath, compareOptions, (err, isEqual) => {
if (err) {
console.log(err)
process.exit(1)
}
results[diffPath] = isEqual ? DIFF_SAME : DIFF_CHANGED
compareNext()
})
}
compareNext()
},
(err, Boolean, equality) => {
if (err) {
reject(err)
return
}
accept(equality)
}
)
break
case 'graphicsmagick': {
// http://www.graphicsmagick.org/GraphicsMagick.html
// https://github.com/aheckmann/gm/blob/master/lib/compare.js
gm.compare(
actualFilename,
expectedFilename,
{
highlightColor: 'RED',
highlightStyle: 'Assign',
file: diffFilename,
},
(err, Boolean, equality) => {
if (err) {
reject(err)
return
}
accept(equality)
}
)
puppeteerHelper.getImage(contentObj.link, imgPath, screenShottingOptions, err => {
if (err) {
log().error({ err, contentId: ctx.contentId }, 'Could not generate an image');
return callback(err);
}
// If the image is solid white don't attach it as a screenshot
gm.compare(
imgPath,
path.resolve(__dirname, '../../../static/link/blank.png'),
0,
(err, isEqual, equality, raw) => {
if (err) {
log().error({ err, contentId: ctx.contentId }, 'Could not compare image');
return callback(err);
}
log().trace({ contentId: ctx.contentId, equality, raw });
if (isEqual) {
log().info({ contentId: ctx.contentId }, 'Not attaching blank screenshot');
return callback();
}
bench('gm', function(next) {
gm.compare(
refImage,
currImage,
{
file: path2,
highlightStyle: 'assign',
highlightColor: '"#ff00ff"'
},
next
);
});
});
promises.push(new Promise(function (resolve, reject) {
gm.compare(file1, file2, {tolerance: 0.05}, function (err, isEqual, mismatch, raw, path1, path2) {
if (err) {
reject(err);
}
assert.ok(mismatch < 0.01, item + ' ' + mismatch);
var file1 = 'test/img/png/' + item;
var file2 = 'test/img/pdf-to-png/' + item;
html.push('<div style="border-bottom:1px solid LightGrey;">');
html.push('<p>' + item + ' - ' + mismatch + '</p>');
html.push('<img src="' + file1 + '" alt="' + item + '">');
html.push('<img src="' + file2 + '" alt="' + item + '">');
html.push('</div>');
resolve();
});
}));
runComparison : function(item, err) {
//compare Master with diff
gm.compare(config.screens+item+".jpg", config.screens+item+".diff.jpg", function (err, isEqual, equality, raw) {
if (err) throw err;
if (equality > 0) {
//images not the same, FAIL.
console.log("FAILED Diff bp:". red , item);
console.log("FAILED equality rate:" . red , equality , "%" . red);
//create .fail
functions.createFail(item);
} else {
//no change, PASS.
console.log("PASSED Diff bp:" . green , item);
}
});
},
createFail : function(item) {
exports.createImageDiff = function(imagePath1, imagePath2, targetImagePath, callback) {
gm.compare(imagePath1, imagePath2, {
file: targetImagePath
}, function(err, isEqual, equality, raw) {
if (err) {
callback(err);
} else {
callback();
}
});
};
return new Promise((resolve, reject) => {
gm.compare(
path1,
path2,
{ ...instanceConfig, file: diffPath },
(err, isEqual) => {
if (err) {
if (typeof err === 'string') {
reject(new Error(err));
} else {
reject(err);
}
} else {
if (isEqual) {
fs.remove(diffPath);
}
resolve(isEqual);
}
createFail : function(item) {
var options = {
highlightColor: 'yellow',
file: config.screens+item+'.fail.jpg'
};
//will overwrite current .fail if necessary.
gm.compare(config.screens+item+".jpg", config.screens+item+".diff.jpg", options, function (err) {
if (err) throw err;
});
}
}