Skip to content

Commit

Permalink
Add isNewScreenshot to results
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Sutton committed Oct 14, 2019
1 parent b2e67ff commit 85be033
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/methods/BaseCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ export default class BaseCompare {
return path.join(runtimeConfigPath, `${name}-${suffix}.json`);
}

createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions) {
createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions, isNewScreenshot) {
return {
misMatchPercentage,
isWithinMisMatchTolerance,
isSameDimensions,
isExactSameImage: misMatchPercentage === 0
isExactSameImage: misMatchPercentage === 0,
isNewScreenshot
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/methods/LocalCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ export default class LocalCompare extends BaseCompare {
const png = compareData.getDiffImage().pack();
await this.writeDiff(png, diffPath);

return this.createResultReport(misMatchPercentage, false, isSameDimensions);
return this.createResultReport(misMatchPercentage, false, isSameDimensions, false);
} else {
log(`Image is within tolerance or the same`);
await fs.remove(diffPath);

return this.createResultReport(misMatchPercentage, true, isSameDimensions);
return this.createResultReport(misMatchPercentage, true, isSameDimensions, false);
}

} else {
log('first run - create reference file');
await fs.outputFile(referencePath, base64Screenshot, 'base64');
return this.createResultReport(0, true, true);
return this.createResultReport(0, true, true, true);
}
}

Expand Down
24 changes: 21 additions & 3 deletions test/unit/methods/LocalCompare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ describe('LocalCompare', function () {
misMatchPercentage: 0,
isWithinMisMatchTolerance: true,
isSameDimensions: true,
isExactSameImage: true
isExactSameImage: true,
isNewScreenshot: false
};
});

it('creates the captured screenshot', async function () {
this.resultNewFile = {
misMatchPercentage: 0,
isWithinMisMatchTolerance: true,
isSameDimensions: true,
isExactSameImage: true
};
});

it('creates the captured screenshot', async function () {
const context = {};
const base64Screenshot = await readAsBase64(path.join(dirFixture, 'image/100x100.png'));

Expand All @@ -85,7 +94,7 @@ describe('LocalCompare', function () {
assert.isTrue(this.getReferenceFile.calledWithExactly(context), 'Reference getter should receive context as arg');

// check image results
assert.deepEqual(results, this.resultIdentical, 'Result should be reported');
assert.deepEqual(results, this.resultNewFile, 'Result should be reported');

// check if reference image was created
const existsReference = await fs.exists(this.referencFile);
Expand Down Expand Up @@ -165,6 +174,7 @@ describe('LocalCompare', function () {
assert.isFalse(resultSecond.isExactSameImage, 'Images should diff');
assert.isFalse(resultSecond.isWithinMisMatchTolerance, 'Images should be marked as diff');
assert.isTrue(resultSecond.isSameDimensions, 'Image dimensioms should be the same');
assert.isFalse(resultSecond.isNewScreenshot, 'Image should not be new screenshot')

// check if reference is still the same
const statsSecond = await fs.stat(this.referencFile);
Expand Down Expand Up @@ -272,6 +282,7 @@ describe('LocalCompare', function () {
assert.isAbove(result.misMatchPercentage, this.misMatchTolerance, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isFalse(result.isWithinMisMatchTolerance, 'Images should be marked as diff');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was created
const existsDiff = await fs.exists(this.diffFile);
Expand Down Expand Up @@ -307,6 +318,7 @@ describe('LocalCompare', function () {
assert.isAtMost(result.misMatchPercentage, this.misMatchTolerance, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isTrue(result.isWithinMisMatchTolerance, 'Diff should be in tolerance');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was not created
const existsDiff = await fs.exists(this.diffFile);
Expand All @@ -321,6 +333,7 @@ describe('LocalCompare', function () {
assert.isAbove(result.misMatchPercentage, this.misMatchTolerance, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isFalse(result.isWithinMisMatchTolerance, 'Images should be marked as diff');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was created
const existsDiff = await fs.exists(this.diffFile);
Expand Down Expand Up @@ -359,6 +372,7 @@ describe('LocalCompare', function () {
assert.isAtMost(result.misMatchPercentage, this.misMatchTolerance, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isTrue(result.isWithinMisMatchTolerance, 'Diff should be in tolerance');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was not created
const existsDiff = await fs.exists(this.diffFile);
Expand All @@ -373,6 +387,7 @@ describe('LocalCompare', function () {
assert.isAbove(result.misMatchPercentage, this.misMatchTolerance, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isFalse(result.isWithinMisMatchTolerance, 'Images should be marked as diff');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was created
const existsDiff = await fs.exists(this.diffFile);
Expand Down Expand Up @@ -424,6 +439,7 @@ describe('LocalCompare', function () {
assert.isAbove(result.misMatchPercentage, 0, 'Images should diff');
assert.isFalse(result.isExactSameImage, 'Images should diff');
assert.isFalse(result.isWithinMisMatchTolerance, 'Diff should not be in tolerance');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was created
const existsDiff = await fs.exists(this.diffFile);
Expand Down Expand Up @@ -457,6 +473,7 @@ describe('LocalCompare', function () {
// check diff results
assert.isTrue(result.isExactSameImage, 'Images should not diff');
assert.isTrue(result.isWithinMisMatchTolerance, 'Diff should be in tolerance');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was not created
const existsDiff = await fs.exists(this.diffFile);
Expand Down Expand Up @@ -494,6 +511,7 @@ describe('LocalCompare', function () {
// check diff results
assert.isTrue(result.isExactSameImage, 'Images should not diff');
assert.isTrue(result.isWithinMisMatchTolerance, 'Diff should be in tolerance');
assert.isFalse(result.isNewScreenshot, 'Image should not be new screenshot');

// check if diff image was not created
const existsDiff = await fs.exists(this.diffFile);
Expand Down

0 comments on commit 85be033

Please sign in to comment.