Skip to content

Commit

Permalink
Merge pull request #6 from zinserjan/delete-diff
Browse files Browse the repository at this point in the history
delete existing/old diff image when image is no longer different
  • Loading branch information
zinserjan authored Jun 19, 2016
2 parents 8bd1d74 + 46066c1 commit 48cc81d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/methods/LocalCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export default class LocalCompare extends BaseCompare {
const misMatchPercentage = Number(compareData.misMatchPercentage);
const misMatchTolerance = _.get(context, 'options.misMatchTolerance', this.misMatchTolerance);

const diffPath = this.getDiffFile(context);

if (misMatchPercentage > misMatchTolerance) {
const diffPath = this.getDiffFile(context);
log(`Image is different! ${misMatchPercentage}%`);
const png = compareData.getDiffImage().pack();
await this.writeDiff(png, diffPath);
Expand All @@ -44,6 +45,7 @@ export default class LocalCompare extends BaseCompare {
} else {
log(`Image is within tolerance or the same. Updating base image`);
await fs.outputFile(referencePath, base64Screenshot, 'base64');
await fs.remove(diffPath);

return this.createResultReport(misMatchPercentage, true, isSameDimensions);
}
Expand Down
27 changes: 27 additions & 0 deletions test/unit/methods/LocalCompare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ describe('LocalCompare', function () {
await compareImages(this.diffFile, path.join(dirFixture, 'image/100x100-diff.png'))
});

it('deletes existing diff image when image is in tolerance now', async function () {
const base64ScreenshotReference = await readAsBase64(path.join(dirFixture, 'image/100x100.png'));
const base64ScreenshotNew = await readAsBase64(path.join(dirFixture, 'image/100x100-rotated.png'));

// 1st run -> create reference
await this.localCompare.afterScreenshot({}, base64ScreenshotReference);

// 2nd run --> create diff image
await this.localCompare.afterScreenshot({}, base64ScreenshotNew);

// check if diff image was created
let existsDiff = await fs.exists(this.diffFile);
assert.isTrue(existsDiff, 'Diff screenshot should exist');

// 3rd run --> update reference image & delete existing diff
const context = {
options: {
misMatchTolerance: 100,
}
};
await this.localCompare.afterScreenshot(context, base64ScreenshotNew);

// check if diff image was deleted
existsDiff = await fs.exists(this.diffFile);
assert.isFalse(existsDiff, 'Diff screenshot should no longer exist');
});

});


Expand Down

0 comments on commit 48cc81d

Please sign in to comment.