diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index c2de32000f8c7e..a5402b4a6084ac 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -195,8 +195,10 @@ function jsToYaml(indent, name, value) { actual, operator, stack, + name, } = value; let errMsg = message ?? ''; + let errName = name; let errStack = stack; let errCode = code; let errExpected = expected; @@ -209,6 +211,7 @@ function jsToYaml(indent, name, value) { if (code === 'ERR_TEST_FAILURE' && kUnwrapErrors.has(failureType)) { errStack = cause?.stack ?? errStack; errCode = cause?.code ?? errCode; + errName = cause?.name ?? errName; if (isAssertionLike(cause)) { errExpected = cause.expected; errActual = cause.actual; @@ -225,6 +228,9 @@ function jsToYaml(indent, name, value) { if (errCode) { result += jsToYaml(indent, 'code', errCode); } + if (errName && errName !== 'Error') { + result += jsToYaml(indent, 'name', errName); + } if (errIsAssertion) { result += jsToYaml(indent, 'expected', errExpected); diff --git a/lib/internal/test_runner/yaml_to_js.js b/lib/internal/test_runner/yaml_to_js.js index 3aa28f9bc2cbfb..6eb193f4afd36e 100644 --- a/lib/internal/test_runner/yaml_to_js.js +++ b/lib/internal/test_runner/yaml_to_js.js @@ -42,9 +42,13 @@ function reConstructError(parsedYaml) { } else { // eslint-disable-next-line no-restricted-syntax cause = new Error(parsedYaml.error); + } + const name = parsedYaml.name ?? 'Error'; + cause.stack = `${name}: ${parsedYaml.error}\n${stack}`; + + if (!isAssertionError && !isTestFailure) { cause.code = parsedYaml.code; } - cause.stack = stack; if (isTestFailure) { error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType); diff --git a/test/message/test_runner_abort.out b/test/message/test_runner_abort.out index 3f1a3c2b7703f1..95a78243e729bf 100644 --- a/test/message/test_runner_abort.out +++ b/test/message/test_runner_abort.out @@ -43,6 +43,7 @@ TAP version 13 failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -62,6 +63,7 @@ TAP version 13 failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -81,6 +83,7 @@ TAP version 13 failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -100,6 +103,7 @@ not ok 1 - promise timeout signal failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 + name: 'TimeoutError' stack: |- * * @@ -113,6 +117,7 @@ not ok 2 - promise abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -168,6 +173,7 @@ not ok 2 - promise abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -187,6 +193,7 @@ not ok 2 - promise abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -206,6 +213,7 @@ not ok 2 - promise abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * @@ -225,6 +233,7 @@ not ok 3 - callback timeout signal failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 + name: 'TimeoutError' stack: |- * * @@ -238,6 +247,7 @@ not ok 4 - callback abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * diff --git a/test/message/test_runner_abort_suite.out b/test/message/test_runner_abort_suite.out index 4dc71da99a766f..06a70bdf012196 100644 --- a/test/message/test_runner_abort_suite.out +++ b/test/message/test_runner_abort_suite.out @@ -67,6 +67,7 @@ not ok 1 - describe timeout signal failureType: 'testAborted' error: 'The operation was aborted due to timeout' code: 23 + name: 'TimeoutError' stack: |- * * @@ -80,6 +81,7 @@ not ok 2 - describe abort signal failureType: 'testAborted' error: 'This operation was aborted' code: 20 + name: 'AbortError' stack: |- * * diff --git a/test/message/test_runner_describe_it.out b/test/message/test_runner_describe_it.out index b1005ff8bc0b7d..41c4e275b5b614 100644 --- a/test/message/test_runner_describe_it.out +++ b/test/message/test_runner_describe_it.out @@ -122,6 +122,7 @@ not ok 14 - async assertion fail true !== false code: 'ERR_ASSERTION' + name: 'AssertionError' expected: false actual: true operator: 'strictEqual' diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out index 1a165c33264e32..2609833304e246 100644 --- a/test/message/test_runner_output.out +++ b/test/message/test_runner_output.out @@ -126,6 +126,7 @@ not ok 13 - async assertion fail true !== false code: 'ERR_ASSERTION' + name: 'AssertionError' expected: false actual: true operator: 'strictEqual' diff --git a/test/message/test_runner_output_cli.out b/test/message/test_runner_output_cli.out index c351b1fa26fc83..72957397c05454 100644 --- a/test/message/test_runner_output_cli.out +++ b/test/message/test_runner_output_cli.out @@ -126,6 +126,7 @@ not ok 13 - async assertion fail true !== false code: 'ERR_ASSERTION' + name: 'AssertionError' expected: false actual: true operator: 'strictEqual'