Skip to content

Commit

Permalink
Don't update golden image if unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Goudet committed Jul 15, 2019
1 parent e5ed119 commit 0aab9f4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions screenshot_helper/screenshot_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export async function compareScreenshot(data, golden, outputFolder = undefined):
const screenshotPath = await writeScreenshot(tempFolder, data);
// check if goldens need to be updated
const update = process.env['UPDATE_GOLDENS'] === '1' || process.env['UPDATE_GOLDENS'] === 'true';
if (update) {
if (update && !fs.existsSync(golden)) {
fs.writeFileSync(golden, fs.readFileSync(screenshotPath));
resolve('Reference image ' + golden +' was successfully updated.');
resolve('Reference image ' + golden + ' was successfully updated.');
return;
}
const goldenName = path.basename(golden);
Expand All @@ -53,7 +53,10 @@ export async function compareScreenshot(data, golden, outputFolder = undefined):
return;
}
if (!equal) {
if (outputFolder) {
if (update) {
fs.writeFileSync(golden, fs.readFileSync(screenshotPath));
resolve('Reference image ' + golden + ' was successfully updated.');
} else if (outputFolder) {
const diffPath = path.join(outputFolder, `diff-${goldenName}`);
looksSame.createDiff({
reference: golden,
Expand Down

0 comments on commit 0aab9f4

Please sign in to comment.