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

Commit

Permalink
feat: add option "buildDiffOpts" to configure building diff image
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Jan 29, 2019
1 parent 520aa5d commit 2c672df
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 4 deletions.
9 changes: 9 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ compareOpts: {
}
```

#### buildDiffOpts
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:
```javascript
buildDiffOpts: {
ignoreAntialiasing: true,
ignoreCaret: true
}
```

* `windowSize` — specify browser window dimensions (i.e. `1600x1200`). If not
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.

Expand Down
15 changes: 15 additions & 0 deletions lib/config/browser-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const getTopLevel = () => {
tolerance: 2.3,
antialiasingTolerance: 0,
compareOpts: {stopOnFirstFail: false},
buildDiffOpts: {
ignoreAntialiasing: true,
ignoreCaret: true
},
sessionsPerBrowser: 1,
suitesPerSession: Infinity,
windowSize: null,
Expand Down Expand Up @@ -240,6 +244,17 @@ function buildBrowserOptions(defaultFactory, extra) {
}
}),

buildDiffOpts: option({
defaultValue: defaultFactory('buildDiffOpts'),
parseEnv: JSON.parse,
parseCli: JSON.parse,
validate: (value) => {
if (!isOptionalObject(value)) {
throw new GeminiError('buildDiffOpts should be object');
}
}
}),

orientation: option({
defaultValue: defaultFactory('orientation'),
validate: (value) => {
Expand Down
8 changes: 5 additions & 3 deletions lib/state-processor/test-state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ module.exports = class TestStateProcessor extends StateProcessor {
return super.exec(state, browserSession, page)
.then((result) => {
if (!result.equal) {
result = this._attachDiffBuilder(result);
const {buildDiffOpts} = browserSession.browser.config;
result = this._attachDiffBuilder(result, buildDiffOpts);
}

emit(Events.TEST_RESULT, result);
});
}

_attachDiffBuilder(result) {
_attachDiffBuilder(result, buildDiffOpts) {
return _.extend(result, {
saveDiffTo: (diffPath) => Image.buildDiff({
reference: result.refImg.path,
current: result.currImg.path,
diff: diffPath,
diffColor: this._diffColor,
tolerance: result.tolerance
tolerance: result.tolerance,
...buildDiffOpts
})
});
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/config-options/config-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,32 @@ describe('config', function() {
});
});

describe('buildDiffOpts', function() {
it('should throw error if "buildDiffOpts" is not a object', () => {
assert.throws(function() {
createBrowserConfig({
buildDiffOpts: 'some-string'
});
}, 'buildDiffOpts should be object');
});

['ignoreAntialiasing', 'ignoreCaret'].forEach(function(option) {
it(`should set "${option}" to "true" by default`, () => {
var config = createBrowserConfig();

assert.equal(config.buildDiffOpts[option], true);
});
});

it('should set provided value', function() {
const config = createBrowserConfig({
buildDiffOpts: {k1: 'v1', k2: 'v2'}
});

assert.deepEqual(config.buildDiffOpts, {k1: 'v1', k2: 'v2'});
});
});

describe('orientation', function() {
it('should be null by default', function() {
var config = createBrowserConfig();
Expand Down
55 changes: 54 additions & 1 deletion test/unit/state-processor/test-state-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Promise = require('bluebird');
const CaptureSession = require('lib/capture-session');
const StateProcessor = require('lib/state-processor/state-processor');
const TestStateProcessor = require('lib/state-processor/test-state-processor');
const {Image} = require('gemini-core');
const util = require('../../util');

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

beforeEach(() => sandbox.stub(StateProcessor.prototype, 'exec'));
beforeEach(() => {
sandbox.stub(StateProcessor.prototype, 'exec');
sandbox.stub(Image, 'buildDiff');
});

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

Expand Down Expand Up @@ -79,5 +83,54 @@ describe('state-processor/test-state-processor', () => {
assert.calledWithExactly(emit, 'testResult', result);
});
});

describe('should build diff image with', () => {
const mkBrowserSession_ = (opts = {}) => _.set({}, 'browser.config', opts);
const mkResult_ = (opts = {}) => {
return _.defaults(opts, {
equal: false,
refImg: {path: '/default-ref/path'},
currImg: {path: '/default-curr/path'}
});
};

it('options from "buildDiffOpts"', () => {
const result = mkResult_();
const buildDiffOpts = {foo: 'bar', baz: 'qux'};
const browserSession = mkBrowserSession_({buildDiffOpts});
const emit = sandbox.stub();

StateProcessor.prototype.exec.returns(Promise.resolve(result));

return exec_({emit, browserSession})
.then(() => {
result.saveDiffTo();

assert.calledOnceWith(
Image.buildDiff,
sinon.match({foo: 'bar', baz: 'qux'})
);
});
});

it('with overriden option from "buildDiffOpts"', () => {
const result = mkResult_({tolerance: 100500});
const buildDiffOpts = {tolerance: 500100};
const browserSession = mkBrowserSession_({buildDiffOpts});
const emit = sandbox.stub();

StateProcessor.prototype.exec.returns(Promise.resolve(result));

return exec_({emit, browserSession})
.then(() => {
result.saveDiffTo();

assert.calledOnceWith(
Image.buildDiff,
sinon.match({tolerance: 500100})
);
});
});
});
});
});

0 comments on commit 2c672df

Please sign in to comment.