-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
By analyzing the blame information on this pull request, we identified @kasperlewau, @ariporad and @sotojuan to be potential reviewers |
return x.notDeepEqual(val, expected, msg); | ||
}; | ||
|
||
function deprecationNotice(oldApi, newApi) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect we'll want something a little more robust :-)
And shall I just say that because the tests for this project are written in tap rather than AVA, I'm coming to appreciate AVA more and more :-) ❤️ |
Thanks for starting the conversation @kentcdodds :) We'll definitely need a codemod if we're going with this. |
Not to start a bikeshedding, but is there any other word we could use that might be even clearer? |
Great to explore options for the best API possible while the topic is open for debate. I have no ideas though... |
Here's an idea: what if I use What do you think? |
I'd be fine with that. |
I think the best criteria by which to judge is this: If someone who has never used tap/AVA/chai/etc is reading the test, what gives them the best chance of understanding what the assertion does without looking at the docs. Part of this includes avoiding ambiguity where possible. If a word could mean two different types of assertions, that's a big knock against it (we won't reach perfection here, because English). Short names should be low on the list of priorities. There is a limit at which something is too long, but a few extra characters is worth any added clarity. |
Couldn't agree more. But I still have no suggestions to a better name than |
Off of the top of my head, here's a couple of candidates (of varying degrees of suck);
The ones that I do like to some extent would be I reckon
I agree, in parts. It's ridiculously short to type, and I think opting for I'm sorry to say I don't have any better suggestions, aside from the list of verbose candidates in my first segment - along with My dream scenario would be for the In all honesty, I find |
My concern with |
Regardless which name we pick we should carefully document which values are considered passing and which aren't. E.g. #630 surfaced that we were requiring constructor equality. I wonder if the "same" or "equal" part is implicit. You're testing an assertion with an actual and an expected value. Given that, how about |
Which would lead to |
I still prefer |
I'm good with We should really have a codemod for this change before releasing it. Anyone interested in trying to make one (I especially encourage community members to try)? Resources: #644 |
Looping in our AST friends: @twada @jfmengels |
Whipped up a quick codemod for this: https://astexplorer.net/#/AbMVMKHZhp I'm happy to put this in a PR. Where should I put the files? Perhaps in |
@spudly I improved your code a bit by providing support for |
@sindresorhus, @jamestalmage, @vdemedes, @novemberborn Opinions about where to put codemods? I was thinking in |
Looks good and nice refactor. Guess I forgot about |
}; | ||
|
||
function deprecationNotice(oldApi, newApi) { | ||
console.warn(`DEPRECATION NOTICE: ${oldApi} has been renamed to ${newApi} and will eventually be removed`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention the codemods here or at least a link to docs that mention it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. Would you like a more robust deprecation abstraction, or is this simple function and console.warn
sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use util.deprecate
.
@kentcdodds We now have a codemod, so this could potentially go into the next release. Would you be able to finish this up and fix the failing tests? |
Could definitely use some help on this to know why tests are failing. It's confusing with mix of I definitely want to make this happen soon! :D |
t.same()
to t.deepEqual()
df2d1d0
to
ef49c0f
Compare
Updated the deprecation to use |
test('.same() should log a deprecation notice', function (t) { | ||
var calledWith; | ||
var originalConsole = console.warn; | ||
console.warn = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that when using util.deprecate
, it actually logs to console.log
which is fine, but I can't seem to get this test to work because when I reassign console.log
it appears that my reassignment is never called. I'm not sure what's going on here... Any tips appreciated.
Alternatively, we can trust that util.deprecate
works and not worry about writing tests for this case... ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like deprecate calls an undocumented method process.emitWarning
.
That ends up causing a warning
event to be emitted on process
, which seems to be handled by writing to console.error
.
So try console.error
?
Or just trust that util.deprecate
works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just trust that
util.deprecate
works.
If everyone's ok with that, I think that's what I wanna do :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js core uses util.deprecate
. So I would trust it.
Alrighty, this should be ready to go I think. Feedback welcome! |
@@ -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.'); |
There was a problem hiding this comment.
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
't.same(value, expected, [message])', | ||
't.notSame(value, expected, [message])', | ||
't.deepEqual(value, expected, [message])', | ||
't.notDeepEqual(value, expected, [message])', |
There was a problem hiding this comment.
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 ¯_(ツ)_/¯
There was a problem hiding this comment.
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).
Also, let me know if you want me to squash and clean things up with the commit message or if you're fine using GitHub's fancy new squash and merge feature :-) |
We will use GH' squash and merge. |
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.`; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
A few notes, mostly related to making sure we are deprecating Once those are cleared up, LGTM. |
Updated PR to respond to @jamestalmage's comments. Thanks! |
b9e601c
to
4a804f7
Compare
*/ | ||
same<U>(value: U, expected: U, message?: string): void; | ||
/** | ||
* Assert that value is not deep equal to expected. (DEPRECATED use `notDeepEqual`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the DEPRECATED
warning to the start?
IDE's use these comments for tooltips. So it would be good to have the warning as prominent as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
LGTM. |
! |
Yay for better UX. Thanks for nudging us towards this and doing the work @kentcdodds :) |
Fantastic! Did we decided on doing truthy/falsy? I'm happy to do that work as well |
Yes. We're going with that. PR super appriciated :) |
Do not merge :-)
This is a work in progress PR just to get the conversation started. There are several tests that are failing and I could use some help there I think.
Thoughts?