From 6481c93aefdc9072edfb2db9cee8fa7c42ec2f43 Mon Sep 17 00:00:00 2001 From: Joseph Gentle Date: Fri, 31 Mar 2017 14:46:07 +1100 Subject: [PATCH] assert: add support for Map and Set in deepEqual assert.deepEqual and assert.deepStrictEqual currently return true for any pair of Maps and Sets regardless of content. This patch adds support in deepEqual and deepStrictEqual to verify the contents of Maps and Sets. Deeo equivalence checking is currently an O(n^2) operation, and worse, it gets slower exponentially if maps and sets were nested. Note that this change breaks compatibility with previous versions of deepEqual and deepStrictEqual if consumers were depending on all maps and sets to be seen as equivalent. The old behaviour was never documented, but nevertheless there are certainly some tests out there which depend on it. Support has stalled because the assert API was frozen, but was recently unfrozen in CTC#63. --- Later squashed in: This change updates the checks for deep equality checking on Map and Set to check all set values / all map keys to see if any of them match the expected result. This change is much slower, but based on the conversation in the pull request its probably the right approach. Fixes: https://github.com/nodejs/node/issues/2309 Refs: https://github.com/substack/tape/issues/342 Refs: https://github.com/nodejs/node/pull/2315 Refs: https://github.com/nodejs/CTC/issues/63 PR-URL: https://github.com/nodejs/node/pull/12142 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung --- doc/api/assert.md | 17 +++- lib/assert.js | 111 +++++++++++++++++++- test/parallel/test-assert-deep.js | 163 +++++++++++++++++++++++++++++- 3 files changed, 287 insertions(+), 4 deletions(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index 868b90445031c5..925108b8fcf028 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -18,6 +18,9 @@ An alias of [`assert.ok()`][].