From 3dfdeeb38f176bb17773730f689bff64b11b615b Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sat, 15 Jul 2017 16:02:53 +0200 Subject: [PATCH] Drop compatibility with pre-10.10.0 type.diff return values The diff method used to return { inline: , diff: }, but that was changed in e22bdef68 with a backwards compatibility hack that installed a self-referencing 'diff' property. I suggest we remove the backwards compatibility in Unexpected 11. --- lib/Unexpected.js | 35 +++++++++----------- lib/UnexpectedError.js | 15 ++++----- lib/makeDiffResultBackwardsCompatible.js | 19 ----------- test/api/addType.spec.js | 42 ------------------------ test/api/fail.spec.js | 21 ------------ 5 files changed, 21 insertions(+), 111 deletions(-) delete mode 100644 lib/makeDiffResultBackwardsCompatible.js diff --git a/lib/Unexpected.js b/lib/Unexpected.js index bef52f2dc..a2597c51f 100644 --- a/lib/Unexpected.js +++ b/lib/Unexpected.js @@ -13,7 +13,6 @@ const defaultDepth = require('./defaultDepth'); const createWrappedExpectProto = require('./createWrappedExpectProto'); const AssertionString = require('./AssertionString'); const throwIfNonUnexpectedError = require('./throwIfNonUnexpectedError'); -const makeDiffResultBackwardsCompatible = require('./makeDiffResultBackwardsCompatible'); function isAssertionArg({ type }) { return type.is('assertion'); @@ -817,15 +816,13 @@ Unexpected.prototype.addType = function(type, childUnexpected) { ); } - return makeDiffResultBackwardsCompatible( - baseType.diff( - actual, - expected, - output.clone(), - (actual, expected) => that.diff(actual, expected, output.clone()), - (value, depth) => output.clone().appendInspected(value, depth), - that.equal.bind(that) - ) + return baseType.diff( + actual, + expected, + output.clone(), + (actual, expected) => that.diff(actual, expected, output.clone()), + (value, depth) => output.clone().appendInspected(value, depth), + that.equal.bind(that) ); }; @@ -1586,16 +1583,14 @@ Unexpected.prototype.diff = function( seen.push(a); } - return makeDiffResultBackwardsCompatible( - this.findCommonType(a, b).diff( - a, - b, - output, - (actual, expected) => - that.diff(actual, expected, output.clone(), recursions - 1, seen), - (v, depth) => output.clone().appendInspected(v, depth), - (actual, expected) => that.equal(actual, expected) - ) + return this.findCommonType(a, b).diff( + a, + b, + output, + (actual, expected) => + that.diff(actual, expected, output.clone(), recursions - 1, seen), + (v, depth) => output.clone().appendInspected(v, depth), + (actual, expected) => that.equal(actual, expected) ); }; diff --git a/lib/UnexpectedError.js b/lib/UnexpectedError.js index b5cead743..24acec176 100644 --- a/lib/UnexpectedError.js +++ b/lib/UnexpectedError.js @@ -1,7 +1,6 @@ const utils = require('./utils'); const defaultDepth = require('./defaultDepth'); const useFullStackTrace = require('./useFullStackTrace'); -const makeDiffResultBackwardsCompatible = require('./makeDiffResultBackwardsCompatible'); const errorMethodBlacklist = [ 'message', @@ -71,14 +70,12 @@ UnexpectedError.prototype.buildDiff = function(options) { const expect = this.expect; return ( this.createDiff && - makeDiffResultBackwardsCompatible( - this.createDiff( - output, - (actual, expected) => expect.diff(actual, expected, output.clone()), - (v, depth) => - output.clone().appendInspected(v, (depth || defaultDepth) - 1), - (actual, expected) => expect.equal(actual, expected) - ) + this.createDiff( + output, + (actual, expected) => expect.diff(actual, expected, output.clone()), + (v, depth) => + output.clone().appendInspected(v, (depth || defaultDepth) - 1), + (actual, expected) => expect.equal(actual, expected) ) ); }; diff --git a/lib/makeDiffResultBackwardsCompatible.js b/lib/makeDiffResultBackwardsCompatible.js deleted file mode 100644 index 379a1928f..000000000 --- a/lib/makeDiffResultBackwardsCompatible.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = function makeDiffResultBackwardsCompatible(diff) { - if (diff) { - if (diff.isMagicPen) { - // New format: { [MagicPen], inline: } - // Make backwards compatible by adding a 'diff' property that points - // to the instance itself. - diff.diff = diff; - } else { - // Old format: { inline: , diff: } - // Upgrade to the new format by moving the inline property to - // the magicpen instance, and remain backwards compatibly by adding - // the diff property pointing to the instance itself. - diff.diff.inline = diff.inline; - diff = diff.diff; - diff.diff = diff; - } - } - return diff; -}; diff --git a/test/api/addType.spec.js b/test/api/addType.spec.js index 56d7de1bd..287e8cb1f 100644 --- a/test/api/addType.spec.js +++ b/test/api/addType.spec.js @@ -220,48 +220,6 @@ describe('addType', function() { ); }); }); - - it('allows adding a type whose diff method returns an old-style { inline: , diff: } object', function() { - clonedExpect.addType({ - name: 'box', - identify(obj) { - return obj && typeof obj === 'object' && obj.isBox; - }, - equal(a, b, equal) { - return a === b || equal(a.value, b.value); - }, - inspect(obj, depth, output, inspect) { - return output - .text('box(') - .append(inspect(obj.value)) - .text(')'); - }, - diff(actual, expected, output, diff) { - return { - inline: true, - diff: output - .text('box(') - .append(diff({ value: actual.value }, { value: expected.value })) - .text(')') - }; - } - }); - - expect( - function() { - clonedExpect(box('abc'), 'to equal', box('abe')); - }, - 'to throw', - "expected box('abc') to equal box('abe')\n" + - '\n' + - 'box({\n' + - " value: 'abc' // should equal 'abe'\n" + - ' //\n' + - ' // -abc\n' + - ' // +abe\n' + - '})' - ); - }); }); describe('#inspect', function() { diff --git a/test/api/fail.spec.js b/test/api/fail.spec.js index d10d374ea..0b7b3869b 100644 --- a/test/api/fail.spec.js +++ b/test/api/fail.spec.js @@ -150,26 +150,5 @@ describe('fail assertion', function() { "expected 'bar' to foo\n" + '\n' + 'custom' ); }); - - it('should support a diff function that uses the old API', function() { - var clonedExpect = expect.clone(); - clonedExpect.addAssertion(' to foo', function(expect, subject) { - expect.fail({ - diff(output, diff, inspect, equal) { - return { - inline: false, - diff: output.text('custom') - }; - } - }); - }); - expect( - function() { - clonedExpect('bar', 'to foo'); - }, - 'to throw', - "expected 'bar' to foo\n" + '\n' + 'custom' - ); - }); }); });