diff --git a/lib/internal/errors.js b/lib/internal/errors.js index c07920ae5d0..6d3b0557803 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -184,6 +184,8 @@ function createErrDiff(actual, expected, operator) { } actualLines.pop(); expectedLines.pop(); + if (actualLines.length === 0 || expectedLines.length === 0) + break; a = actualLines[actualLines.length - 1]; b = expectedLines[expectedLines.length - 1]; } diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 869011908c3..f3f0012f842 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -31,6 +31,7 @@ const { EOL } = require('os'); const EventEmitter = require('events'); const { errorCache } = require('internal/errors'); const { writeFileSync, unlinkSync } = require('fs'); +const { inspect } = require('util'); const a = assert; assert.ok(a.AssertionError.prototype instanceof Error, @@ -565,6 +566,17 @@ common.expectsError( () => assert.deepEqual(Array(12).fill(1), Array(12).fill(2)), { message }); + const obj1 = {}; + const obj2 = { loop: 'forever' }; + obj2[inspect.custom] = () => '{}'; + // No infinite loop and no custom inspect. + assert.throws(() => assert.deepEqual(obj1, obj2), { + message: `${start}\n` + + `${actExp}\n` + + '\n' + + ' {}' + }); + // notDeepEqual tests message = 'Identical input passed to notDeepStrictEqual:\n[\n 1\n]'; assert.throws(