From e573c99bfdec6686ef8209b96e71226266ad792b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 1 May 2019 22:49:04 +0200 Subject: [PATCH] assert: fix `assert.fail()` stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure the error message visible in the error stack created when using `assert.fail()` without any arguments or the message set to `undefined` or `null` as only argument. That was masked before due to other changes. PR-URL: https://github.com/nodejs/node/pull/27525 Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso --- lib/assert.js | 14 ++++++-------- test/parallel/test-assert-fail.js | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index ffa71bfad8d412..dece9a08a78142 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -92,9 +92,10 @@ function innerFail(obj) { function fail(actual, expected, message, operator, stackStartFn) { const argsLen = arguments.length; - let internalMessage; - if (argsLen === 0) { - internalMessage = 'Failed'; + let internalMessage = false; + if (actual == null && argsLen <= 1) { + internalMessage = true; + message = 'Failed'; } else if (argsLen === 1) { message = actual; actual = undefined; @@ -118,14 +119,11 @@ function fail(actual, expected, message, operator, stackStartFn) { actual, expected, operator: operator === undefined ? 'fail' : operator, - stackStartFn: stackStartFn || fail + stackStartFn: stackStartFn || fail, + message }; - if (message !== undefined) { - errArgs.message = message; - } const err = new AssertionError(errArgs); if (internalMessage) { - err.message = internalMessage; err.generatedMessage = true; } throw err; diff --git a/test/parallel/test-assert-fail.js b/test/parallel/test-assert-fail.js index 51c69372dd8e5d..e2003f2ce91da8 100644 --- a/test/parallel/test-assert-fail.js +++ b/test/parallel/test-assert-fail.js @@ -13,7 +13,8 @@ assert.throws( operator: 'fail', actual: undefined, expected: undefined, - generatedMessage: true + generatedMessage: true, + stack: /Failed/ } );