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

Commit 2c672df

Browse files
committed
feat: add option "buildDiffOpts" to configure building diff image
1 parent 520aa5d commit 2c672df

5 files changed

Lines changed: 109 additions & 4 deletions

File tree

doc/config.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ compareOpts: {
225225
}
226226
```
227227

228+
#### buildDiffOpts
229+
Extra options for building diff image. See [looks-same](https://github.com/gemini-testing/looks-same#building-diff-image) documentation for the list of available options. Default values are:
230+
```javascript
231+
buildDiffOpts: {
232+
ignoreAntialiasing: true,
233+
ignoreCaret: true
234+
}
235+
```
236+
228237
* `windowSize` — specify browser window dimensions (i.e. `1600x1200`). If not
229238
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.
230239

lib/config/browser-options.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const getTopLevel = () => {
2626
tolerance: 2.3,
2727
antialiasingTolerance: 0,
2828
compareOpts: {stopOnFirstFail: false},
29+
buildDiffOpts: {
30+
ignoreAntialiasing: true,
31+
ignoreCaret: true
32+
},
2933
sessionsPerBrowser: 1,
3034
suitesPerSession: Infinity,
3135
windowSize: null,
@@ -240,6 +244,17 @@ function buildBrowserOptions(defaultFactory, extra) {
240244
}
241245
}),
242246

247+
buildDiffOpts: option({
248+
defaultValue: defaultFactory('buildDiffOpts'),
249+
parseEnv: JSON.parse,
250+
parseCli: JSON.parse,
251+
validate: (value) => {
252+
if (!isOptionalObject(value)) {
253+
throw new GeminiError('buildDiffOpts should be object');
254+
}
255+
}
256+
}),
257+
243258
orientation: option({
244259
defaultValue: defaultFactory('orientation'),
245260
validate: (value) => {

lib/state-processor/test-state-processor.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ module.exports = class TestStateProcessor extends StateProcessor {
1717
return super.exec(state, browserSession, page)
1818
.then((result) => {
1919
if (!result.equal) {
20-
result = this._attachDiffBuilder(result);
20+
const {buildDiffOpts} = browserSession.browser.config;
21+
result = this._attachDiffBuilder(result, buildDiffOpts);
2122
}
2223

2324
emit(Events.TEST_RESULT, result);
2425
});
2526
}
2627

27-
_attachDiffBuilder(result) {
28+
_attachDiffBuilder(result, buildDiffOpts) {
2829
return _.extend(result, {
2930
saveDiffTo: (diffPath) => Image.buildDiff({
3031
reference: result.refImg.path,
3132
current: result.currImg.path,
3233
diff: diffPath,
3334
diffColor: this._diffColor,
34-
tolerance: result.tolerance
35+
tolerance: result.tolerance,
36+
...buildDiffOpts
3537
})
3638
});
3739
}

test/unit/config-options/config-options.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,32 @@ describe('config', function() {
916916
});
917917
});
918918

919+
describe('buildDiffOpts', function() {
920+
it('should throw error if "buildDiffOpts" is not a object', () => {
921+
assert.throws(function() {
922+
createBrowserConfig({
923+
buildDiffOpts: 'some-string'
924+
});
925+
}, 'buildDiffOpts should be object');
926+
});
927+
928+
['ignoreAntialiasing', 'ignoreCaret'].forEach(function(option) {
929+
it(`should set "${option}" to "true" by default`, () => {
930+
var config = createBrowserConfig();
931+
932+
assert.equal(config.buildDiffOpts[option], true);
933+
});
934+
});
935+
936+
it('should set provided value', function() {
937+
const config = createBrowserConfig({
938+
buildDiffOpts: {k1: 'v1', k2: 'v2'}
939+
});
940+
941+
assert.deepEqual(config.buildDiffOpts, {k1: 'v1', k2: 'v2'});
942+
});
943+
});
944+
919945
describe('orientation', function() {
920946
it('should be null by default', function() {
921947
var config = createBrowserConfig();

test/unit/state-processor/test-state-processor.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Promise = require('bluebird');
66
const CaptureSession = require('lib/capture-session');
77
const StateProcessor = require('lib/state-processor/state-processor');
88
const TestStateProcessor = require('lib/state-processor/test-state-processor');
9+
const {Image} = require('gemini-core');
910
const util = require('../../util');
1011

1112
describe('state-processor/test-state-processor', () => {
@@ -27,7 +28,10 @@ describe('state-processor/test-state-processor', () => {
2728
return mkTestStateProc_().exec(opts.state, opts.browserSession, opts.page, opts.emit);
2829
};
2930

30-
beforeEach(() => sandbox.stub(StateProcessor.prototype, 'exec'));
31+
beforeEach(() => {
32+
sandbox.stub(StateProcessor.prototype, 'exec');
33+
sandbox.stub(Image, 'buildDiff');
34+
});
3135

3236
afterEach(() => sandbox.restore());
3337

@@ -79,5 +83,54 @@ describe('state-processor/test-state-processor', () => {
7983
assert.calledWithExactly(emit, 'testResult', result);
8084
});
8185
});
86+
87+
describe('should build diff image with', () => {
88+
const mkBrowserSession_ = (opts = {}) => _.set({}, 'browser.config', opts);
89+
const mkResult_ = (opts = {}) => {
90+
return _.defaults(opts, {
91+
equal: false,
92+
refImg: {path: '/default-ref/path'},
93+
currImg: {path: '/default-curr/path'}
94+
});
95+
};
96+
97+
it('options from "buildDiffOpts"', () => {
98+
const result = mkResult_();
99+
const buildDiffOpts = {foo: 'bar', baz: 'qux'};
100+
const browserSession = mkBrowserSession_({buildDiffOpts});
101+
const emit = sandbox.stub();
102+
103+
StateProcessor.prototype.exec.returns(Promise.resolve(result));
104+
105+
return exec_({emit, browserSession})
106+
.then(() => {
107+
result.saveDiffTo();
108+
109+
assert.calledOnceWith(
110+
Image.buildDiff,
111+
sinon.match({foo: 'bar', baz: 'qux'})
112+
);
113+
});
114+
});
115+
116+
it('with overriden option from "buildDiffOpts"', () => {
117+
const result = mkResult_({tolerance: 100500});
118+
const buildDiffOpts = {tolerance: 500100};
119+
const browserSession = mkBrowserSession_({buildDiffOpts});
120+
const emit = sandbox.stub();
121+
122+
StateProcessor.prototype.exec.returns(Promise.resolve(result));
123+
124+
return exec_({emit, browserSession})
125+
.then(() => {
126+
result.saveDiffTo();
127+
128+
assert.calledOnceWith(
129+
Image.buildDiff,
130+
sinon.match({tolerance: 500100})
131+
);
132+
});
133+
});
134+
});
82135
});
83136
});

0 commit comments

Comments
 (0)