diff --git a/index.d.ts b/index.d.ts index eb851b2c2..aa47f2831 100644 --- a/index.d.ts +++ b/index.d.ts @@ -120,15 +120,27 @@ export interface AssertContext { /** * Assert that value is deep equal to expected. */ - same(value: U, expected: U, message?: string): void; + deepEqual(value: U, expected: U, message?: string): void; /** * Assert that value is not deep equal to expected. */ - notSame(value: U, expected: U, message?: string): void; + notDeepEqual(value: U, expected: U, message?: string): void; /** * Assert that function throws an error or promise rejects. * @param error Can be a constructor, regex, error message or validation function. */ + /** + * DEPRECATED, use `deepEqual`. Assert that value is deep equal to expected. + */ + same(value: U, expected: U, message?: string): void; + /** + * DEPRECATED use `notDeepEqual`. Assert that value is not deep equal to expected. + */ + notSame(value: U, expected: U, message?: string): void; + /** + * Assert that function throws an error or promise rejects. + * @param error Can be a constructor, regex, error message or validation function. + */ throws(value: Promise<{}>, error?: ErrorValidator, message?: string): Promise; throws(value: () => void, error?: ErrorValidator, message?: string): any; /** diff --git a/lib/assert.js b/lib/assert.js index 6ce7122db..21953c536 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -60,12 +60,12 @@ x.not = function (val, expected, msg) { test(val !== expected, create(val, expected, '!==', msg, x.not)); }; -x.same = function (val, expected, msg) { - test(deepEqual(val, expected), create(val, expected, '===', msg, x.same)); +x.deepEqual = function (val, expected, msg) { + test(deepEqual(val, expected), create(val, expected, '===', msg, x.deepEqual)); }; -x.notSame = function (val, expected, msg) { - test(!deepEqual(val, expected), create(val, expected, '!==', msg, x.notSame)); +x.notDeepEqual = function (val, expected, msg) { + test(!deepEqual(val, expected), create(val, expected, '!==', msg, x.notDeepEqual)); }; x.throws = function (fn, err, msg) { @@ -130,8 +130,6 @@ x.notThrows = function (fn, msg) { } }; -x.doesNotThrow = util.deprecate(x.notThrows, 't.doesNotThrow is renamed to t.notThrows. The old name still works, but will be removed in AVA 1.0.0. Update your references.'); - x.regex = function (contents, regex, msg) { test(regex.test(contents), create(regex, contents, '===', msg, x.regex)); }; @@ -139,3 +137,14 @@ x.regex = function (contents, regex, msg) { x.ifError = x.error = function (err, msg) { test(!err, create(err, 'Error', '!==', msg, x.ifError)); }; + +/* + * deprecated APIs + */ +x.doesNotThrow = util.deprecate(x.notThrows, getDeprecationNotice('doesNotThrow()', 'notThrows()')); +x.same = util.deprecate(x.deepEqual, getDeprecationNotice('same()', 'deepEqual()')); +x.notSame = util.deprecate(x.notDeepEqual, getDeprecationNotice('notSame()', 'notDeepEqual()')); + +function getDeprecationNotice(oldApi, newApi) { + return 'DEPRECATION NOTICE: ' + oldApi + ' has been renamed to ' + newApi + ' and will eventually be removed. See https://github.com/jamestalmage/ava-codemods to help upgrade your codebase automatically.'; +} diff --git a/lib/enhance-assert.js b/lib/enhance-assert.js index 17f98a159..67eb0698f 100644 --- a/lib/enhance-assert.js +++ b/lib/enhance-assert.js @@ -8,9 +8,12 @@ module.exports.PATTERNS = [ 't.false(value, [message])', 't.is(value, expected, [message])', 't.not(value, expected, [message])', + 't.deepEqual(value, expected, [message])', + 't.notDeepEqual(value, expected, [message])', + 't.regex(contents, regex, [message])', + // deprecated apis 't.same(value, expected, [message])', - 't.notSame(value, expected, [message])', - 't.regex(contents, regex, [message])' + 't.notSame(value, expected, [message])' ]; module.exports.NON_ENHANCED_PATTERNS = [ diff --git a/readme.md b/readme.md index 382cc86bb..5a989d0e1 100644 --- a/readme.md +++ b/readme.md @@ -51,7 +51,7 @@ Translations: [EspaƱol](https://github.com/sindresorhus/ava-docs/blob/master/es import test from 'ava'; test(t => { - t.same([1, 2], [1, 2]); + t.deepEqual([1, 2], [1, 2]); }); ``` @@ -762,11 +762,11 @@ Assert that `value` is equal to `expected`. Assert that `value` is not equal to `expected`. -### `.same(value, expected, [message])` +### `.deepEqual(value, expected, [message])` Assert that `value` is deep equal to `expected`. -### `.notSame(value, expected, [message])` +### `.notDeepEqual(value, expected, [message])` Assert that `value` is not deep equal to `expected`. diff --git a/test/assert.js b/test/assert.js index c02b46d36..6f5cf558e 100644 --- a/test/assert.js +++ b/test/assert.js @@ -119,51 +119,51 @@ test('.not()', function (t) { t.end(); }); -test('.same()', function (t) { +test('.deepEqual()', function (t) { t.doesNotThrow(function () { - assert.same({a: 'a'}, {a: 'a'}); + assert.deepEqual({a: 'a'}, {a: 'a'}); }); t.doesNotThrow(function () { - assert.same(['a', 'b'], ['a', 'b']); + assert.deepEqual(['a', 'b'], ['a', 'b']); }); t.throws(function () { - assert.same({a: 'a'}, {a: 'b'}); + assert.deepEqual({a: 'a'}, {a: 'b'}); }); t.throws(function () { - assert.same(['a', 'b'], ['a', 'a']); + assert.deepEqual(['a', 'b'], ['a', 'a']); }); t.throws(function () { - assert.same([['a', 'b'], 'c'], [['a', 'b'], 'd']); + assert.deepEqual([['a', 'b'], 'c'], [['a', 'b'], 'd']); }, / 'c' ].*? 'd' ]/); t.throws(function () { var circular = ['a', 'b']; circular.push(circular); - assert.same([circular, 'c'], [circular, 'd']); + assert.deepEqual([circular, 'c'], [circular, 'd']); }, / 'c' ].*? 'd' ]/); t.end(); }); -test('.notSame()', function (t) { +test('.notDeepEqual()', function (t) { t.doesNotThrow(function () { - assert.notSame({a: 'a'}, {a: 'b'}); + assert.notDeepEqual({a: 'a'}, {a: 'b'}); }); t.doesNotThrow(function () { - assert.notSame(['a', 'b'], ['c', 'd']); + assert.notDeepEqual(['a', 'b'], ['c', 'd']); }); t.throws(function () { - assert.notSame({a: 'a'}, {a: 'a'}); + assert.notDeepEqual({a: 'a'}, {a: 'a'}); }); t.throws(function () { - assert.notSame(['a', 'b'], ['a', 'b']); + assert.notDeepEqual(['a', 'b'], ['a', 'b']); }); t.end(); @@ -259,7 +259,7 @@ test('.ifError()', function (t) { t.end(); }); -test('.same() should not mask RangeError from underlying assert', function (t) { +test('.deepEqual() should not mask RangeError from underlying assert', function (t) { var Circular = function () { this.test = this; }; @@ -268,11 +268,11 @@ test('.same() should not mask RangeError from underlying assert', function (t) { var b = new Circular(); t.throws(function () { - assert.notSame(a, b); + assert.notDeepEqual(a, b); }); t.doesNotThrow(function () { - assert.same(a, b); + assert.deepEqual(a, b); }); t.end(); diff --git a/test/fixture/circular-reference-on-assertion.js b/test/fixture/circular-reference-on-assertion.js index d9a0da855..3603efe86 100644 --- a/test/fixture/circular-reference-on-assertion.js +++ b/test/fixture/circular-reference-on-assertion.js @@ -3,5 +3,5 @@ import test from '../../'; test(t => { const circular = ['a', 'b']; circular.push(circular); - t.same([circular, 'c'], [circular, 'd']); + t.deepEqual([circular, 'c'], [circular, 'd']); }); diff --git a/test/fixture/pkg-conf/defaults/test.js b/test/fixture/pkg-conf/defaults/test.js index 756cd4260..b5464b732 100644 --- a/test/fixture/pkg-conf/defaults/test.js +++ b/test/fixture/pkg-conf/defaults/test.js @@ -6,5 +6,5 @@ test(t => { t.is(opts.failFast, false); t.is(opts.serial, false); t.is(opts.cacheEnabled, true); - t.same(opts.require, []); + t.deepEqual(opts.require, []); }); diff --git a/test/fixture/pkg-conf/pkg-overrides/actual.js b/test/fixture/pkg-conf/pkg-overrides/actual.js index dce9a16b1..5320272e0 100644 --- a/test/fixture/pkg-conf/pkg-overrides/actual.js +++ b/test/fixture/pkg-conf/pkg-overrides/actual.js @@ -7,7 +7,7 @@ test(t => { t.is(opts.failFast, true); t.is(opts.serial, true); t.is(opts.cacheEnabled, false); - t.same(opts.require, [ + t.deepEqual(opts.require, [ path.join(__dirname, "required.js") ]); }); diff --git a/test/fixture/pkg-conf/precedence/c.js b/test/fixture/pkg-conf/precedence/c.js index 51ef8b553..c0c75968f 100644 --- a/test/fixture/pkg-conf/precedence/c.js +++ b/test/fixture/pkg-conf/precedence/c.js @@ -7,8 +7,8 @@ test('foo', t => { t.is(opts.failFast, false); t.is(opts.serial, false); t.is(opts.cacheEnabled, true); - t.same(opts.match, ['foo*']); - t.same(opts.require, [ + t.deepEqual(opts.match, ['foo*']); + t.deepEqual(opts.require, [ path.join(__dirname, "required.js") ]); }); diff --git a/test/fixture/serial.js b/test/fixture/serial.js index fe6c7688d..29aee03d1 100644 --- a/test/fixture/serial.js +++ b/test/fixture/serial.js @@ -17,5 +17,5 @@ test.cb('second', t => { }); test(t => { - t.same(tests, ['first', 'second']); + t.deepEqual(tests, ['first', 'second']); }); diff --git a/test/hooks.js b/test/hooks.js index 8a49780e6..d438b26f3 100644 --- a/test/hooks.js +++ b/test/hooks.js @@ -270,12 +270,12 @@ test('shared context', function (t) { runner.test(function (a) { a.context.arr.push('b'); - a.same(a.context.arr, ['a', 'b']); + a.deepEqual(a.context.arr, ['a', 'b']); }); runner.afterEach(function (a) { a.context.arr.push('c'); - a.same(a.context.arr, ['a', 'b', 'c']); + a.deepEqual(a.context.arr, ['a', 'b', 'c']); }); runner.run({}).then(function () { diff --git a/test/test.js b/test/test.js index 68db6dbe1..8638f25e6 100644 --- a/test/test.js +++ b/test/test.js @@ -166,7 +166,7 @@ test('handle non-assertion errors even when planned', function (t) { test('handle testing of arrays', function (t) { var result = ava(function (a) { - a.same(['foo', 'bar'], ['foo', 'bar']); + a.deepEqual(['foo', 'bar'], ['foo', 'bar']); }).run(); t.is(result.passed, true); @@ -176,7 +176,7 @@ test('handle testing of arrays', function (t) { test('handle falsy testing of arrays', function (t) { var result = ava(function (a) { - a.notSame(['foo', 'bar'], ['foo', 'bar', 'cat']); + a.notDeepEqual(['foo', 'bar'], ['foo', 'bar', 'cat']); }).run(); t.is(result.passed, true); @@ -186,7 +186,7 @@ test('handle falsy testing of arrays', function (t) { test('handle testing of objects', function (t) { var result = ava(function (a) { - a.same({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar'}); + a.deepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar'}); }).run(); t.is(result.passed, true); @@ -196,7 +196,7 @@ test('handle testing of objects', function (t) { test('handle falsy testing of objects', function (t) { var result = ava(function (a) { - a.notSame({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar', cat: 'cake'}); + a.notDeepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar', cat: 'cake'}); }).run(); t.is(result.passed, true);