-
Notifications
You must be signed in to change notification settings - Fork 30k
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
lib: generalize handling in assert.deepEqual() #3124
Conversation
Whenever there is a change suggested in this module I judge that by this comment #2315 (comment). If we go by that, this change is not necessary as assert is not a general purpose module. |
Is this a semver-major? @rvagg |
@thefourtheye Yes, if that's the standard, then this is probably not necessary. I say "probably" because I wonder if any of the checks on things like More importantly, perhaps: If the |
@Trott, @domenic It's a bit too late for making the It's directly used by at least 11% of modules on npmjs (a quick grep for Update: Without the |
Yes, has to be semver-major I reckon, also I'm not sure this approach is consistent, have a look at how |
JavaScript is an awful language sometimes haha. I agree with Rod's sentiment, but I think the frequency of use would warrant this enough. If nothing else, we could probably get it into |
I'm thinking I should close this PR and instead update the docs to reflect that:
|
866e5f8
to
c8855db
Compare
@rvagg, @Fishrock123: Since it's already semver-major, might an appropriate course of action be to run RegExp (and maybe a few other things) through this more rigorous checking? Assuming it doesn't bork any of our tests, it seems like that might streamline the code a bit. It's semver-major already, so why not take the opportunity to streamline the code a bit? |
Just pushed something to remove special handling for Error, Buffer, and RegExp. Added a tiny bit of hopefully-straightforward special handling for Array and String (which is to ignore the length property if they are being compared against something that doesn't have a length property). All tests still pass. Still semver major, but I feel much better about this. Seems less hacky. PTAL @rvagg @Fishrock123 Still could use a doc update to clarify some finer points, but that could be a separate PR, as this is all consistent with existing docs. |
32009e7
to
f7fe2cc
Compare
yeah, I don't know, this is pretty significant, perhaps we need to include @nodejs/tsc on this for more opinions |
This PR looks like it's attempting to achieve some sort of theoretical completeness. Which I don't disagree with, but on this route you must seriously consider also doing proper comparisons of any |
Error objects have non-enumerable properties. So, unexpectedly, assert.deepEqual(new Error('a'), new Error('b')) will not throw an AssertionError. This commit changes that behavior. Fixes: nodejs#3122
f7fe2cc
to
a5b09a5
Compare
@trevnorris Symbols added. Thanks for that! |
This seems better to me.
Nobody suggested making it internal or deprecating it. Just, not changing it. |
@domenic Can you elaborate a bit on why you favor the doc-only approach but not a deprecation? I'm assuming deprecation could just mean sticking a deprecation notice in the docs but not doing anything at all in the code. Maybe we just have different ideas about what "deprecation" might entail. The close-in-favor-of-doc-PR was how I felt when this change was adding additional special handling for |
I just think that contributors and core team members should not spend time working on the assert module. They especially shouldn't be doing so in a way that changes behavior in observable ways that could break programs using it. Maybe it would be helpful to add something to the docs saying its behavior won't be changed, so that people don't file issues on it. And maybe it'd even be interesting to explain why---because the assert module is developed so that Node.js can test itself, not so that you can write your own tests. I don't know if you'd call that a deprecation or not. |
@domenic Thanks, that's very clear. I guess regardless of what happens to this PR, the doc change is a good idea. |
Proposed doc-only update at #3330. I'm still in favor of the changes here, but regardless, the docs should reflect the current status. |
Based on the audio from the most recent TSC meeting, I'm going to close this PR. |
Assert is now locked. Userland alternatives should be used. Assert is for testing Node.js itself. Document potentially surprising use of enumerable properties only in deep equality assertions. Ref: nodejs#3124 Ref: nodejs#3122 PR-URL: nodejs#3330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Assert is now locked. Userland alternatives should be used. Assert is for testing Node.js itself. Document potentially surprising use of enumerable properties only in deep equality assertions. Ref: #3124 Ref: #3122 PR-URL: #3330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Assert is now locked. Userland alternatives should be used. Assert is for testing Node.js itself. Document potentially surprising use of enumerable properties only in deep equality assertions. Ref: #3124 Ref: #3122 PR-URL: #3330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Assert is now locked. Userland alternatives should be used. Assert is for testing Node.js itself. Document potentially surprising use of enumerable properties only in deep equality assertions. Ref: #3124 Ref: #3122 PR-URL: #3330 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Error
objects have non-enumerable properties. So, unexpectedly,assert.deepEqual(new Error('a'), new Error('b'));
will not throw. Thiscommit changes that behavior.
Fixes: #3122