diff --git a/index.js b/index.js index 20f2f92..3f94ae7 100644 --- a/index.js +++ b/index.js @@ -116,12 +116,13 @@ const getToleranceFromOpts = (opts) => { }; const prepareOpts = (opts) => { - opts.tolerance = getToleranceFromOpts(opts); + const tolerance = getToleranceFromOpts(opts); - return _.defaults(opts, { + return _.defaults({}, opts, { ignoreCaret: true, ignoreAntialiasing: true, - antialiasingTolerance: 0 + antialiasingTolerance: 0, + tolerance: tolerance }); }; @@ -228,11 +229,7 @@ exports.createDiff = function saveDiff(opts, callback) { }; exports.colors = (color1, color2, opts) => { - opts = opts || {}; - - if (opts.tolerance === undefined) { - opts.tolerance = JND; - } + opts = _.defaults({}, opts, {tolerance: JND}); const comparator = makeCIEDE2000Comparator(opts.tolerance); diff --git a/test/test.js b/test/test.js index d9740ae..fac0aef 100644 --- a/test/test.js +++ b/test/test.js @@ -62,6 +62,15 @@ describe('looksSame', () => { }); }); + it('should not modify input options', (done) => { + const opts = {}; + + looksSame(srcPath('ref.png'), srcPath('same.png'), opts, () => { + expect(Object.keys(opts)).to.deep.equal([]); + done(); + }); + }); + forFilesAndBuffers((getImage) => { it('should return true for similar images', (done) => { looksSame(getImage('ref.png'), getImage('same.png'), (error, {equal}) => { @@ -398,6 +407,24 @@ describe('createDiff', () => { }).to.throw(TypeError); }); + it('should not modify input options', (done) => { + const opts = { + reference: srcPath('ref.png'), + current: srcPath('same.png'), + diff: this.tempName, + highlightColor: '#ff00ff' + }; + + looksSame.createDiff(opts, () => { + expect(Object.keys(opts)).to.deep.equal( + ['reference', 'current', 'diff', 'highlightColor'] + ); + done(); + }); + + // If we got here, the call didn't attempt to modify opts + }); + it('should format images', (done) => { sandbox.spy(utils, 'formatImages'); @@ -762,6 +789,17 @@ describe('createDiff', () => { }); describe('colors', () => { + it('should not modify input options', () => { + const opts = {}; + + looksSame.colors( + {R: 255, G: 0, B: 0}, + {R: 255, G: 0, B: 0}, + opts); + + expect(Object.keys(opts)).to.deep.equal([]); + }); + it('should return true for same colors', () => { expect( looksSame.colors(