0f2f25c5d9
* update drone to use cypress 12 image * upgrade cypress to 12 in core * cypress config actually valid * update @grafana/e2e imports and add lint rule * ignore grafana-e2e from betterer now it's deprecated * fix remaining type errors * fix failing tests * remove unnecessary tsconfig * remove unnecessary comment * update enterprise suite commands to work * add cypress config to CODEOWNERS * export setTimeRange in utils * remove @grafana/e2e from core deps * try running the command through yarn * move CMD to scripts * Update cloud-data-sources e2e image * Update paths --------- Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
50 lines
1.7 KiB
JavaScript
50 lines
1.7 KiB
JavaScript
'use strict';
|
|
const BlinkDiff = require('blink-diff');
|
|
const { resolve } = require('path');
|
|
|
|
// @todo use npmjs.com/pixelmatch or an available cypress plugin
|
|
const compareScreenshots = async ({ config, screenshotsFolder, specName }) => {
|
|
const name = config.name || config; // @todo use `??`
|
|
const threshold = config.threshold || 0.001; // @todo use `??`
|
|
|
|
const imageAPath = `${screenshotsFolder}/${specName}/${name}.png`;
|
|
const imageBPath = resolve(`${screenshotsFolder}/../expected/${specName}/${name}.png`);
|
|
|
|
const imageOutputPath = screenshotsFolder.endsWith('actual') ? imageAPath.replace('.png', '.diff.png') : undefined;
|
|
|
|
const { code } = await new Promise((resolve, reject) => {
|
|
new BlinkDiff({
|
|
imageAPath,
|
|
imageBPath,
|
|
imageOutputPath,
|
|
threshold,
|
|
thresholdType: BlinkDiff.THRESHOLD_PERCENT,
|
|
}).run((error, result) => {
|
|
if (error) {
|
|
reject(error);
|
|
} else {
|
|
resolve(result);
|
|
}
|
|
});
|
|
});
|
|
|
|
if (code <= 1) {
|
|
let msg = `\nThe screenshot [${imageAPath}] differs from [${imageBPath}]`;
|
|
msg += '\n';
|
|
msg += '\nCheck the Artifacts tab in the CircleCi build output for the actual screenshots.';
|
|
msg += '\n';
|
|
msg += '\n If the difference between expected and outcome is NOT acceptable then do the following:';
|
|
msg += '\n - Check the code for changes that causes this difference, fix that and retry.';
|
|
msg += '\n';
|
|
msg += '\n If the difference between expected and outcome is acceptable then do the following:';
|
|
msg += '\n - Replace the expected image with the outcome and retry.';
|
|
msg += '\n';
|
|
throw new Error(msg);
|
|
} else {
|
|
// Must return a value
|
|
return true;
|
|
}
|
|
};
|
|
|
|
module.exports = compareScreenshots;
|