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

Commit

Permalink
Merge c5f1145 into 4f3f652
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Jan 29, 2019
2 parents 4f3f652 + c5f1145 commit 31d3802
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 16 deletions.
23 changes: 19 additions & 4 deletions doc/config.md
Expand Up @@ -15,7 +15,10 @@ calibrate: false
tolerance: 3.5
antialiasingTolerance: 0,
compareOpts:
stopOnFirstFail: true
stopOnFirstFail: false
buildDiffOpts:
ignoreAntialiasing: true
ignoreCaret: true
httpTimeout: 5000
sessionRequestTimeout: 60000
sessionQuitTimeout: 5000
Expand Down Expand Up @@ -215,9 +218,21 @@ Settings list:

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

* `compareOpts` — extra options for images comparing. It's an Object with following fields:
* `[stopOnFirstFail] {Boolean}` Only first pixel will be found if this option is true
See [looks-same](https://github.com/gemini-testing/looks-same#comparing-images) documentation for the list of options.
* `compareOpts` — extra options for comparing images. See [looks-same](https://github.com/gemini-testing/looks-same#comparing-images) documentation for the list of available options. Default values are:
```javascript
compareOpts: {
stopOnFirstFail: false
}
```

#### 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
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
9 changes: 6 additions & 3 deletions lib/state-processor/test-state-processor.js
Expand Up @@ -17,21 +17,24 @@ module.exports = class TestStateProcessor extends StateProcessor {
return super.exec(state, browserSession, page)
.then((result) => {
if (!result.equal) {
result = this._attachDiffBuilder(result);
const {buildDiffOpts, antialiasingTolerance} = browserSession.browser.config;
result = this._attachDiffBuilder(result, {buildDiffOpts, antialiasingTolerance});
}

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

_attachDiffBuilder(result) {
_attachDiffBuilder(result, {buildDiffOpts, antialiasingTolerance}) {
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,
antialiasingTolerance,
...buildDiffOpts
})
});
}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"gemini-configparser": "^1.0.0",
"gemini-core": "3.2.0",
"gemini-core": "^3.3.0",
"gemini-coverage": "^2.0.0",
"graceful-fs": "^4.1.11",
"handlebars": "^4.0.5",
Expand Down
26 changes: 26 additions & 0 deletions test/unit/config-options/config-options.test.js
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
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 31d3802

Please sign in to comment.