From 15fa5b88de291cb291e702233c17e474735cd9e0 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 28 Feb 2023 00:05:58 +0200 Subject: [PATCH 1/3] test_runner: fix reconstruction of errors extracted from YAML --- lib/internal/test_runner/reporter/tap.js | 6 ++++++ lib/internal/test_runner/yaml_to_js.js | 4 +++- test/message/test_runner_abort.out | 10 ++++++++++ test/message/test_runner_abort_suite.out | 2 ++ test/message/test_runner_describe_it.out | 1 + test/message/test_runner_output.out | 1 + test/message/test_runner_output_cli.out | 1 + 7 files changed, 24 insertions(+), 1 deletion(-) 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..d550bfc7bb027d 100644 --- a/lib/internal/test_runner/yaml_to_js.js +++ b/lib/internal/test_runner/yaml_to_js.js @@ -44,9 +44,11 @@ function reConstructError(parsedYaml) { cause = new Error(parsedYaml.error); cause.code = parsedYaml.code; } - cause.stack = stack; + const name = parsedYaml.name ?? 'Error'; + cause.stack = `${name}: ${parsedYaml.error}\n${stack}`; if (isTestFailure) { + if (!isAssertionError) delete cause.code; error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType); error.stack = stack; } 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 2de7664bd24d1a..4502c89fdae086 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' From 0dc93700f4995dfb694d6c4f89c73e84f7e5fa49 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 28 Feb 2023 22:03:07 +0200 Subject: [PATCH 2/3] CR --- lib/internal/test_runner/yaml_to_js.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/yaml_to_js.js b/lib/internal/test_runner/yaml_to_js.js index d550bfc7bb027d..e356ed5ac1538c 100644 --- a/lib/internal/test_runner/yaml_to_js.js +++ b/lib/internal/test_runner/yaml_to_js.js @@ -47,8 +47,11 @@ function reConstructError(parsedYaml) { const name = parsedYaml.name ?? 'Error'; cause.stack = `${name}: ${parsedYaml.error}\n${stack}`; + if (!isAssertionError && !isTestFailure) { + cause.code = parsedYaml.code; + } + if (isTestFailure) { - if (!isAssertionError) delete cause.code; error = new ERR_TEST_FAILURE(cause, parsedYaml.failureType); error.stack = stack; } From a34f86f6c651489d11458834c023abdce5f50e21 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 28 Feb 2023 23:12:11 +0200 Subject: [PATCH 3/3] CR --- lib/internal/test_runner/yaml_to_js.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/test_runner/yaml_to_js.js b/lib/internal/test_runner/yaml_to_js.js index e356ed5ac1538c..6eb193f4afd36e 100644 --- a/lib/internal/test_runner/yaml_to_js.js +++ b/lib/internal/test_runner/yaml_to_js.js @@ -42,7 +42,6 @@ function reConstructError(parsedYaml) { } else { // eslint-disable-next-line no-restricted-syntax cause = new Error(parsedYaml.error); - cause.code = parsedYaml.code; } const name = parsedYaml.name ?? 'Error'; cause.stack = `${name}: ${parsedYaml.error}\n${stack}`;