aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-assert-deep.js
AgeCommit message (Collapse)Author
2019-08-09test: assert: add failing deepEqual test for faked boxed primitivesJordan Harband
PR-URL: https://github.com/nodejs/node/pull/29029 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12assert: print more lines in the error diffRuben Bridgewater
So far consequitive identical lines were collapsed if there were at least three. Now they are only collapsed from five identical lines on. This also simplifies the implementation a tiny bit by abstracting some logic. PR-URL: https://github.com/nodejs/node/pull/28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12assert: fix error diffRuben Bridgewater
In some edge cases an identical line could be printed twice. This is now fixed by changing the algorithm a bit. It will now verify how many lines were identical before the current one. PR-URL: https://github.com/nodejs/node/pull/28058 Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-05-13assert: loose deep equal should not compare symbol propertiesRuben Bridgewater
This is the way it's currently documented and that seems appropriate for loose equal assertions. The change was not intentional. Fixes: https://github.com/nodejs/node/issues/27652 PR-URL: https://github.com/nodejs/node/pull/27653 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
2019-05-05assert: refine assertion messageRuben Bridgewater
This makes sure that the error message is more appropriate than before by checking closer what operator is used and which is not. It also increases the total number of lines printed to the user. PR-URL: https://github.com/nodejs/node/pull/27525 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-03-27benchmark,doc,lib: capitalize more commentsRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/26849 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2019-03-23errors: update error nameRuben Bridgewater
This updates all Node.js errors by removing the `code` being part of the `name` property. Instead, the name is just changed once on instantiation, the stack is accessed to create the stack as expected and then the `name` property is set back to it's original form. PR-URL: https://github.com/nodejs/node/pull/26738 Fixes: https://github.com/nodejs/node/issues/26669 Fixes: https://github.com/nodejs/node/issues/20253 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-03-10benchmark,doc,lib,test: capitalize commentsRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/26483 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-02-14test: increase coverage for assertion_error.jsRich Trott
Add a test for long strings and assert.notDeepEqual() to cover code that truncates output when it is longer than 1024 characters. PR-URL: https://github.com/nodejs/node/pull/26065 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2019-01-27assert: adjust loose assertionsRuben Bridgewater
This changes the loose deep equal comparison by using the same logic as done in the strict deep equal comparison besides comparing primitives loosely, not comparing symbol properties and not comparing the prototype. `assert.deepEqual` is still commenly used and this is likely the biggest pitfall. Most changes are only minor and won't have a big impact besides likely fixing user expectations. PR-URL: https://github.com/nodejs/node/pull/25008 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2019-01-10util: add null prototype support for dateAnto Aravinth
PR-URL: https://github.com/nodejs/node/pull/25144 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-12-27util: make inspect aware of RegExp subclasses and null prototypeRuben Bridgewater
This adds support for inspect to distinguish regular expression subclasses and ones with null prototype from "normal" regular expressions. PR-URL: https://github.com/nodejs/node/pull/25192 Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-12-21test: remove unnecessary eslint-disable commentsRich Trott
PR-URL: https://github.com/nodejs/node/pull/25119 Refs: https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-12-18assert: inspect gettersRuben Bridgewater
While asserting two objects the descriptor is not taken into account. Therefore getters will be triggered as such. This makes sure they are also highlighted in the error message instead of potentially looking identical while the return value of the getter is actually different. PR-URL: https://github.com/nodejs/node/pull/25004 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-12-10assert,util: harden comparisonRuben Bridgewater
The former algorithm used checks which were unsafe. Most of these have been replaced with alternatives that can not be manipulated or fooled that easily. PR-URL: https://github.com/nodejs/node/pull/24831 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
2018-12-03test: improve comparison coverage to 100%Ruben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/24749 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-12-03assert,util: fix sparse array comparisonRuben Bridgewater
Comparing sparse arrays did not work properly. That is fixed and tests were added to verify that everything works as expected. This had an impact on `util.isDeepStrictEqual()` and `assert.deepStrictEqual()` and their counterpart `assert.notDeepStrictEqual()`. PR-URL: https://github.com/nodejs/node/pull/24749 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-12-03assert: fix loose deepEqual map comparisonRuben Bridgewater
Loose map comparison had an logic error. It will now be properly compared. PR-URL: https://github.com/nodejs/node/pull/24749 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-12-03test: increase assert test coverageRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/24745 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-11-11test : compare objects not identical by referenceMarie Terrier
PR-URL: https://github.com/nodejs/node/pull/24189 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-09-27assert: reduce diff noiseRuben Bridgewater
Assertion errors that produce a diff show a diff for identical entries in case one side of the comparison has more object properties than the other one. Those lines are now taken into account and will not show up as diverging lines anymore. Refs: https://github.com/nodejs/node/issues/22763 PR-URL: https://github.com/nodejs/node/pull/23048 Refs: https://github.com/nodejs/node/issues/22763 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-09-27assert: switch `inputs` to `values`Ruben Bridgewater
The wording seems clearer when using `values` instead of `inputs`. PR-URL: https://github.com/nodejs/node/pull/23056 Refs: https://github.com/nodejs/node/issues/22763 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-09-19assert: improve diff outputRuben Bridgewater
The output is now a tiny bit improved by sorting object properties when inspecting the values that are compared with each other. That reduces the overall diff for identical objects with a different property insertion order. PR-URL: https://github.com/nodejs/node/pull/22788 Refs: https://github.com/nodejs/node/issues/22763 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-09-05assert: fix loose set and map comparisonRuben Bridgewater
The fast path did not anticipate different ways to express a loose equal string value (e.g., 1n == '+0001'). This is now fixed with the downside that all primitives that could theoretically have equal entries must go through a full comparison. Only some strings, symbols, undefined, null and NaN can be detected in a fast path as those entries have a strictly limited set of possible equal entries. PR-URL: https://github.com/nodejs/node/pull/22495 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
2018-08-20util,assert: improve performanceRuben Bridgewater
This significantly improves regular and typed array performance by not checking the indices keys anymore. This can be done with a V8 API that allows to only retrieve the non indices property keys. PR-URL: https://github.com/nodejs/node/pull/22197 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-08-15util,assert: improve comparison performanceRuben Bridgewater
This adds a smarter logic to compare object keys (including symbols) and it also skips the object key comparison for (typed) arrays, if possible. Besides that it adds a fast path for empty objects, arrays, sets and maps and fast paths for sets and maps with an unequal size. On top of that a few functions are now safer to call by using uncurryThis and by caching the actual function. Overall, this is a significant performance boost for comparisons. PR-URL: https://github.com/nodejs/node/pull/22258 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
2018-08-12test: improve test coverage for comparisonsRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/22212 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-08-12util,assert: fix boxed primitives bugRuben Bridgewater
Currently the comparison could throw an error in case a boxed primitive has no valueOf function on one side of the assert call. PR-URL: https://github.com/nodejs/node/pull/22243 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: George Adams <george.adams@uk.ibm.com>
2018-08-09assert: fix loose assert with map and setRuben Bridgewater
There was an oversight when checking the possible loose comparisons. This is now fixed by also accepting `''` instead of `0` or `false`. PR-URL: https://github.com/nodejs/node/pull/22145 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-08-09assert: improve loose assertion messageRuben Bridgewater
So far the error message from a loose assertion is not always very informative and could be misleading. This is fixed by: * showing more from the actual error message * having a better error description * not using custom inspection * inspecting a higher depth * inspecting the full array instead of up to 100 entries PR-URL: https://github.com/nodejs/node/pull/22155 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-08-04assert: multiple improvementsRuben Bridgewater
1) Switched + / - and red / green in diffs. It seems like that style is more natural to most people. 2) Short primitives do not use the diff anymore. Especially short numbers can be read well like 1 !== 2. Cases that can not be displayed like that (e.g., -0 and +0) use the regular diff output. 3) Improved error descriptions. It was not always clear what the messages stood for. That should now be resolved. 4) Added a position indicator for single lines in case a tty is used and the line is shorter than the visual columns. 5) Color detection is now done by checking stderr instead of stdout. PR-URL: https://github.com/nodejs/node/pull/21628 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2018-05-14test: disable colors in test-assert-deep.jscjihrig
When test/parallel/test-assert-deep.js is run with a TTY as stdout, color codes in assertion messages cause the test to fail. This commit disables colors when stdout is a TTY. PR-URL: https://github.com/nodejs/node/pull/20695 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-14assert: improve default error messagesRuben Bridgewater
This improves the error messages for: - assert.notDeepStrictEqual - assert.deepStrictEqual - assert.notStrictEqual - assert.strictEqual Those will now always use the same error message as used in the strict mode. PR-URL: https://github.com/nodejs/node/pull/19467 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-02-16test: minor refactoringRuben Bridgewater
Add punctuation and comments about code that should not throw. Also remove a obsolete test and refactor some tests. PR-URL: https://github.com/nodejs/node/pull/18669 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-02-16test: remove assert.doesNotThrow()Ruben Bridgewater
There is actually no reason to use `assert.doesNotThrow()` in the tests. If a test throws, just let the error bubble up right away instead of first catching it and then rethrowing it. PR-URL: https://github.com/nodejs/node/pull/18669 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-02-10test: refactor assert testRuben Bridgewater
This adds puctiations to the comments, uses a capital letters for the first character, removes a few obsolete comments and switches to assert.ok when suitable. It also moves all `assert.deepEqual()` and `assert.deepStrictEqual()` tests to the appropriate file. PR-URL: https://github.com/nodejs/node/pull/18610 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-10-29test: add block scoping to test-assert-deepRich Trott
Add block scoping to test-assert-deep.js to reduce likelihood of one test case having side effects that affect another test case. PR-URL: https://github.com/nodejs/node/pull/16532 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-09-19assert: handle enumerable symbol keysRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/15169 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-09-15assert: use Same-value equality in deepStrictEqualRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/15398 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
2017-09-12assert: fix boxed primitives in deepStrictEqualRuben Bridgewater
Unbox all primitives and compare them as well instead of only comparing boxed strings. PR-URL: https://github.com/nodejs/node/pull/15050 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-09-05assert: use SameValueZero in deepStrictEqualRuben Bridgewater
Comparing NaN will not throw anymore. PR-URL: https://github.com/nodejs/node/pull/15036 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-09-01assert: handle errors properly with deep*EqualRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/15001 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-08-28assert: handle sparse arrays in deepStrictEqualRuben Bridgewater
Detect sparse array ends and add a fail early path for unequal array length. PR-URL: https://github.com/nodejs/node/pull/15027 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-08-01test: clean up some assert deepEqual testsRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/14491 Fixes: https://github.com/nodejs/node/issues/14441 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-08-01assert: fix deepEqual inconsistenciesRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/14491 Fixes: https://github.com/nodejs/node/issues/14441 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-07-21lib,src: fix consistent spacing inside bracesSebastiaan Deckers
PR-URL: https://github.com/nodejs/node/pull/14162 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-19assert: improve deepEqual Set and Map worst caseRuben Bridgewater
This change improves the algorithm for the worst case from O(n^2) to O(n log n) by using a lazily initiated set with object or not strict equal primitives keys. In addition a few comments got fixed and a statement simplified. PR-URL: https://github.com/nodejs/node/pull/14258 Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-08test: add optional throw fn to expectsErrorRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/14089 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-06-21test: fix RegExp nitsVse Mozhet Byt
* Remove needless RegExp flag In fixed case, `/g` flag is needless in the boolean context. * Remove needless RegExp capturing Use non-capturing grouping or remove capturing completely when: * capturing is useless per se, e.g. in test() check; * captured groups are not used afterward at all; * some of the later captured groups are not used afterward. * Use test, not match/exec in boolean context match() and exec() return a complicated object, unneeded in a boolean context. * Do not needlessly repeat RegExp creation This commit takes RegExp creation out of cycles and other repetitions. As long as the RegExp does not use /g flag and match indices, we are safe here. In tests, this fix hardly gives a significant performance gain, but it increases clarity and maintainability, reassuring some RegExps to be identical. RegExp in functions are not taken out of their functions: while these functions are called many times and their RegExps are recreated with each call, the performance gain in test cases does not seem to be worth decreasing function self-dependency. PR-URL: https://github.com/nodejs/node/pull/13770 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-06-05assert: fix deepEqual similar sets and maps bugJoseph Gentle
This fixes a bug where deepEqual and deepStrictEqual would have incorrect behaviour in sets and maps containing multiple equivalent keys. PR-URL: https://github.com/nodejs/node/pull/13426 Fixes: https://github.com/nodejs/node/issues/13347 Refs: https://github.com/nodejs/node/pull/12142 Reviewed-By: Refael Ackermann <refack@gmail.com>