Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename t.same() to t.deepEqual() #686

Merged
merged 6 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ export interface AssertContext {
/**
* Assert that value is deep equal to expected.
*/
same<U>(value: U, expected: U, message?: string): void;
deepEqual<U>(value: U, expected: U, message?: string): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will removing these cause compiler errors for TypeScript? Does TypeScript have a way to deprecate in a d.t.s file?

// @SamVerschueren

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just left the original there and commented that they're deprecated. ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably the only way to handle it. Looks like TS has a two year old issue on the topic:
microsoft/TypeScript#390

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the best way to handle this situations as well. It will indeed throw a compile error because it could not find the same method.

/**
* Assert that value is not deep equal to expected.
*/
notSame<U>(value: U, expected: U, message?: string): void;
notDeepEqual<U>(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.
Expand Down
22 changes: 16 additions & 6 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -130,12 +130,22 @@ 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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this down to the other deprecated APIs

test(regex.test(contents), create(regex, contents, '===', msg, x.regex));
};

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.`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't transpile AVA. Can't use string templates on Node 0.10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know. Will update.

}
4 changes: 2 additions & 2 deletions lib/enhance-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports.PATTERNS = [
't.false(value, [message])',
't.is(value, expected, [message])',
't.not(value, expected, [message])',
't.same(value, expected, [message])',
't.notSame(value, expected, [message])',
't.deepEqual(value, expected, [message])',
't.notDeepEqual(value, expected, [message])',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit made things tricky for me in test/test.js which asserts t.is(result.result.assertCount, 1); and there was no real way for me to know that this is what causes assertCount to increment. Still not sure I follow but this fixed it so ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The power-assert enhancement actually has callbacks (onSuccess, onFailure) that are called with the result of each assertion. That is where we implement assertion tracking.

I think you should probably keep t.same and t.notSame in the patterns until they are officially removed. Otherwise this will break assertionCount for them. Maybe add a test that ensures the assertion count is tracked for those (which we will remove when we drop support).

't.regex(contents, regex, [message])'
];

Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
```

Expand Down Expand Up @@ -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`.

Expand Down
30 changes: 15 additions & 15 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
};
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/circular-reference-on-assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/defaults/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
});
2 changes: 1 addition & 1 deletion test/fixture/pkg-conf/pkg-overrides/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]);
});
4 changes: 2 additions & 2 deletions test/fixture/pkg-conf/precedence/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]);
});
2 changes: 1 addition & 1 deletion test/fixture/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ test.cb('second', t => {
});

test(t => {
t.same(tests, ['first', 'second']);
t.deepEqual(tests, ['first', 'second']);
});
4 changes: 2 additions & 2 deletions test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down