Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit bdb3aab

Browse files
committed
feat: pass diff bounds to error from looks-same
1 parent 86624ce commit bdb3aab

8 files changed

Lines changed: 2446 additions & 2686 deletions

File tree

doc/config.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ desiredCapabilities:
1313
commonThing: value
1414
calibrate: false
1515
tolerance: 3.5
16-
antialiasingTolerance: 0
16+
antialiasingTolerance: 0,
17+
compareOpts:
18+
stopOnFirstFail: true
1719
httpTimeout: 5000
1820
sessionRequestTimeout: 60000
1921
sessionQuitTimeout: 5000
@@ -213,6 +215,10 @@ Settings list:
213215

214216
* `antialiasingTolerance` — read about this option in [looks-same](https://github.com/gemini-testing/looks-same#comparing-images-with-ignoring-antialiasing).
215217

218+
* `compareOpts` — extra options for images comparing. It's an Object with following fields:
219+
* `[stopOnFirstFail] {Boolean}` Only first pixel will be found if this option is true
220+
See [looks-same](https://github.com/gemini-testing/looks-same#comparing-images) documentation for the list of options.
221+
216222
* `windowSize` — specify browser window dimensions (i.e. `1600x1200`). If not
217223
specified, the size of the window depends on WebDriver. :warning: You can't set specific resolutions for browser Opera or mobile platforms. They use only full-screen resolution.
218224

lib/config/browser-options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const getTopLevel = () => {
2525
screenshotsDir: 'gemini/screens',
2626
tolerance: 2.3,
2727
antialiasingTolerance: 0,
28+
compareOpts: {stopOnFirstFail: false},
2829
sessionsPerBrowser: 1,
2930
suitesPerSession: Infinity,
3031
windowSize: null,
@@ -228,6 +229,17 @@ function buildBrowserOptions(defaultFactory, extra) {
228229

229230
compositeImage: booleanOption(defaultFactory('compositeImage')),
230231

232+
compareOpts: option({
233+
defaultValue: defaultFactory('compareOpts'),
234+
parseEnv: JSON.parse,
235+
parseCli: JSON.parse,
236+
validate: (value) => {
237+
if (!isOptionalObject(value)) {
238+
throw new GeminiError('CompareOpts should be object');
239+
}
240+
}
241+
}),
242+
231243
orientation: option({
232244
defaultValue: defaultFactory('orientation'),
233245
validate: (value) => {

lib/state-processor/capture-processor/capture-processor.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ module.exports = class CaptureProcessor {
4949
_compareImages(capture, opts) {
5050
const {refImg} = opts;
5151
const currImg = {path: temp.path({suffix: '.png'}), size: capture.image.getSize()};
52-
const compareOpts = {
52+
const imageCompareOpts = {
5353
canHaveCaret: capture.canHaveCaret,
5454
pixelRatio: opts.pixelRatio,
5555
tolerance: opts.tolerance,
56-
antialiasingTolerance: opts.antialiasingTolerance
56+
antialiasingTolerance: opts.antialiasingTolerance,
57+
compareOpts: opts.compareOpts
5758
};
5859

5960
return capture.image.save(currImg.path)
60-
.then(() => Image.compare(currImg.path, refImg.path, compareOpts))
61-
.then((isEqual) => {
62-
return isEqual
61+
.then(() => Image.compare(currImg.path, refImg.path, imageCompareOpts))
62+
.then(({equal, diffBounds}) => {
63+
return equal
6364
? this._onEqualHandler(refImg, currImg)
64-
: this._onDiffHandler(refImg, currImg);
65+
: this._onDiffHandler(refImg, currImg, diffBounds);
6566
});
6667
}
6768
};

lib/state-processor/capture-processor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports.create = (type) => {
3838
.onReference()
3939
.onNoReference(throwNoRefError)
4040
.onEqual((refImg, currImg) => ({refImg, currImg, equal: true}))
41-
.onDiff((refImg, currImg) => ({refImg, currImg, equal: false}));
41+
.onDiff((refImg, currImg, diffBounds) => ({refImg, currImg, diffBounds, equal: false}));
4242
}
4343

4444
if (type === 'new-updater') {

lib/state-processor/state-processor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module.exports = class StateProcessor {
3333
refImg: {path: browserConfig.getScreenshotPath(state.suite, state.name), size: null},
3434
pixelRatio: page.pixelRatio,
3535
antialiasingTolerance: browserConfig.antialiasingTolerance,
36-
tolerance
36+
tolerance,
37+
compareOpts: browserConfig.compareOpts
3738
},
3839
temp: temp.serialize()
3940
};

0 commit comments

Comments
 (0)