Don't call assert.deepEqual.format when the assertion will succeed

This commit is contained in:
André Bargull 2024-12-18 11:05:56 +01:00 committed by Ms2ger
parent c3cbc32745
commit 900c80295e
1 changed files with 9 additions and 4 deletions

View File

@ -8,10 +8,15 @@ defines: [assert.deepEqual]
assert.deepEqual = function(actual, expected, message) {
var format = assert.deepEqual.format;
assert(
assert.deepEqual._compare(actual, expected),
`Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`
);
var mustBeTrue = assert.deepEqual._compare(actual, expected);
// format can be slow when `actual` or `expected` are large objects, like for
// example the global object, so only call it when the assertion will fail.
if (mustBeTrue !== true) {
message = `Expected ${format(actual)} to be structurally equal to ${format(expected)}. ${(message || '')}`;
}
assert(mustBeTrue, message);
};
(function() {