-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
util,assert: expose util.isDeepStrictEqual() #16084
Conversation
For reference, here are things similar to this functionality (that already exists in Node.js core but is not currently exposed without throwing assertion errors) being reimplemented in userland multiple times. I'm sure there are more examples
(edited by @vsemozhetbyt: fix formatting) |
@refack Can you explain a bit more about us not supporting the non-strict version? I know we (mostly) don't use it in core and we even have a lint rule to flag it. Is that what you mean by not supporting it? |
Yes, I planned on implementing this on my own as well, so I am definitely +1 on adding this in general. I strongly oppose adding the losse variation though. It was a bad idea to ever implement this and I recommend to only have We do support the loose version but we should not. And even if we want to add support for that, I would rather add a optional options object to the function instead of using a separate function name. I am not completely sure if it makes sense to pretty much copy all the assert tests though. It would probably be enough to move them and only test that the assert version actually throws. It would reduce the amount of tests needed. I would also like the documentation to be more expressive but we can also improve that after the feature itself has landed. |
I actually worked a lot on assert before because of adding exactly this. This is a long needed feature for Node and many libraries will likely benefit by this. |
As @BridgeAR there has been minimal work done to improve the non-strict variant. So IMHO it's frozen as-is and not actively supported. If the language comes up with new primitives, I'm not sure how quickly we'll implement their comparison in the non-strict variant. Just an example: > assert.deepStrictEqual(new Number(1), new Number(2));
AssertionError [ERR_ASSERTION]: [Number: 1] deepStrictEqual [Number: 2]
at repl:1:8
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:440:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:282:10)
at REPLServer.Interface._line (readline.js:631:8)
> assert.deepEqual(new Number(1), new Number(2));
undefined or > assert.deepStrictEqual(NaN, NaN);
undefined
> assert.deepEqual(NaN, NaN);
AssertionError [ERR_ASSERTION]: NaN deepEqual NaN
at repl:1:8
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at REPLServer.defaultEval (repl.js:242:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:466:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:287:10)
at REPLServer.Interface._line (readline.js:642:8) |
I'm also a little uncertain as to what use exposing a |
No argument from me on not exposing the Should it be Or should it be Or should it be both? That is, I'm not super-excited about any of these options, but we should be careful about which one we pick because we will probably be stuck with it forever once it's out there. |
🚲 🏠: I'm a big fan of consistency and not a fan of aliases so I'd dig |
|
39d48da
to
d0e49a2
Compare
|
Argh! Left out the test file before. One more time... |
CI passed. This has one approval. It's been open for a few days. In theory it can land. I'd be more comfortable with a bit more review, though. I'll start by pinging the people listed for |
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.
LGTM if CI is happy. I've definitely needed this before :]
I would prefer not to use the name |
Since most people seem to not have an issue with the current name, I will not block this any further. |
It's been 12 days since the last CI run, so it seems prudent to do another one before even considering landing... |
Provide `util.isDeepStrictEqual()` that works like `assert.deepStrictEqual()` but returns a boolean rather than throwing an error. Several userland modules have needed this functionality and implemented it independently. This functionality already exists in Node.js core, so this exposes it for use by modules. Modules that have needed this functionality include `lodash`, `concordance` (used by `ava`), and `qunit`. PR-URL: nodejs#16084 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Landed in 3673208. |
Provide `util.isDeepStrictEqual()` that works like `assert.deepStrictEqual()` but returns a boolean rather than throwing an error. Several userland modules have needed this functionality and implemented it independently. This functionality already exists in Node.js core, so this exposes it for use by modules. Modules that have needed this functionality include `lodash`, `concordance` (used by `ava`), and `qunit`. PR-URL: nodejs/node#16084 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Should this be backported to |
I'm inclined to not backport as it depends on other semver-major commits. But I could see the case for perhaps avoiding future merge conflicts. But on balance, I'm inclined to treat this as 9.0.0-and-above-only. |
Provide `util.isDeepStrictEqual()` that works like `assert.deepStrictEqual()` but returns a boolean rather than throwing an error. Several userland modules have needed this functionality and implemented it independently. This functionality already exists in Node.js core, so this exposes it for use by modules. Modules that have needed this functionality include `lodash`, `concordance` (used by `ava`), and `qunit`. PR-URL: nodejs/node#16084 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
I personally would like this to be backported to 8.x. I think it would be good to have this feature there as well. Backporting will not be trivial though. |
If someone would like to backport then I'm happy to land it on v8.x. |
Ok, I am going to do that. |
When the deep(Strict)Equal comparison functions were moved to an internal module, a variable named `current` was replaced with `val1`. That accidentally also replaced a few "currently"s in comments. Refs: nodejs#16084
When the deep(Strict)Equal comparison functions were moved to an internal module, a variable named `current` was replaced with `val1`. That accidentally also replaced a few "currently"s in comments. Refs: #16084 PR-URL: #21436 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
When the deep(Strict)Equal comparison functions were moved to an internal module, a variable named `current` was replaced with `val1`. That accidentally also replaced a few "currently"s in comments. Refs: #16084 PR-URL: #21436 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Provide
util.isDeepStrictEqual()
that works likeassert.deepStrictEqual()
but returns a bollean rather than throwing an error.Several userland modules have needed this functionality and implemented
independently. This functionality already exists in Node.js core, so
this exposes it for use by modules. Modules that have needed this
functionality include
lodash
,concordance
(used byava
), andqunit
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
util