diff --git a/doc/config.md b/doc/config.md index 4c525a5b4..063044c6d 100644 --- a/doc/config.md +++ b/doc/config.md @@ -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 @@ -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. diff --git a/lib/config/browser-options.js b/lib/config/browser-options.js index ba473f0e0..08fa3460b 100644 --- a/lib/config/browser-options.js +++ b/lib/config/browser-options.js @@ -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, @@ -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) => { diff --git a/lib/state-processor/test-state-processor.js b/lib/state-processor/test-state-processor.js index fcb36d82f..3a02a6ac8 100644 --- a/lib/state-processor/test-state-processor.js +++ b/lib/state-processor/test-state-processor.js @@ -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 }) }); } diff --git a/test/unit/config-options/config-options.test.js b/test/unit/config-options/config-options.test.js index af98ff290..4585b1212 100644 --- a/test/unit/config-options/config-options.test.js +++ b/test/unit/config-options/config-options.test.js @@ -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(); diff --git a/test/unit/state-processor/test-state-processor.js b/test/unit/state-processor/test-state-processor.js index e5a62787c..a2707101d 100644 --- a/test/unit/state-processor/test-state-processor.js +++ b/test/unit/state-processor/test-state-processor.js @@ -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', () => { @@ -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()); @@ -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}) + ); + }); + }); + }); }); });