Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete existing/old diff image when image is no longer different #6

Merged
merged 1 commit into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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