From 900c80295e0dccd4035beaaf68e25aba1d372069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 18 Dec 2024 11:05:56 +0100 Subject: [PATCH] Don't call assert.deepEqual.format when the assertion will succeed --- harness/deepEqual.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/harness/deepEqual.js b/harness/deepEqual.js index 0cd0a49dac..b695c89580 100644 --- a/harness/deepEqual.js +++ b/harness/deepEqual.js @@ -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() {