diff options
author | Moshe Atlow <moshe@atlow.co.il> | 2023-03-02 00:16:39 +0200 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2023-04-10 22:18:20 -0400 |
commit | 524eaf5488c172736b2b6739c635f02fd7350e6d (patch) | |
tree | 56c0c216ff3d67d5c1154f5f60afd5b8ce17033e | |
parent | 0f33bb09615cc1bf1e834b059f8cbfc47084e975 (diff) | |
download | node-new-524eaf5488c172736b2b6739c635f02fd7350e6d.tar.gz |
test_runner: fix reconstruction of errors extracted from YAML
PR-URL: https://github.com/nodejs/node/pull/46872
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | lib/internal/test_runner/reporter/tap.js | 6 | ||||
-rw-r--r-- | lib/internal/test_runner/yaml_to_js.js | 6 | ||||
-rw-r--r-- | test/message/test_runner_abort.out | 10 | ||||
-rw-r--r-- | test/message/test_runner_abort_suite.out | 2 | ||||
-rw-r--r-- | test/message/test_runner_describe_it.out | 1 | ||||
-rw-r--r-- | test/message/test_runner_output.out | 1 | ||||
-rw-r--r-- | test/message/test_runner_output_cli.out | 1 |
7 files changed, 26 insertions, 1 deletions
diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index c2de32000f..a5402b4a60 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 ?? '<unknown error>'; + 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 3aa28f9bc2..6eb193f4af 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 3f1a3c2b77..95a78243e7 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 4dc71da99a..06a70bdf01 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 b1005ff8bc..41c4e275b5 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 1a165c3326..2609833304 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 c351b1fa26..72957397c0 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' |