Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: incorrect unwrapping of errors in after() when using the tap reporter #48941

Closed
mcollina opened this issue Jul 27, 2023 · 5 comments · Fixed by #48942
Closed

test_runner: incorrect unwrapping of errors in after() when using the tap reporter #48941

mcollina opened this issue Jul 27, 2023 · 5 comments · Fixed by #48942
Labels
confirmed-bug Issues with confirmed bugs. test_runner Issues and PRs related to the test runner subsystem.

Comments

@mcollina
Copy link
Member

mcollina commented Jul 27, 2023

Consider this test:

const test = require('node:test')

test('should print the error', (t) => {
  t.after(async () => {
    throw new Error('kaboom')
  })
})

If I run it normally, I get:

✖ should print the error (0.880917ms)
  Error: kaboom
      at TestContext.<anonymous> (/Users/matteo/tmp/bug.js:5:11)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:580:25)
      at TestHook.run (node:internal/test_runner/test:759:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:516:20
      at async Test.runHook (node:internal/test_runner/test:514:7)
      at async after (node:internal/test_runner/test:542:9)
      at async Test.run (node:internal/test_runner/test:590:7)
      at async startSubtest (node:internal/test_runner/harness:204:3)

ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 40.280833

✖ failing tests:

✖ should print the error (0.880917ms)
  Error: kaboom
      at TestContext.<anonymous> (/Users/matteo/tmp/bug.js:5:11)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:580:25)
      at TestHook.run (node:internal/test_runner/test:759:18)
      at TestHook.run (node:internal/util:500:12)
      at node:internal/test_runner/test:516:20
      at async Test.runHook (node:internal/test_runner/test:514:7)
      at async after (node:internal/test_runner/test:542:9)
      at async Test.run (node:internal/test_runner/test:590:7)
      at async startSubtest (node:internal/test_runner/harness:204:3)

If I run in a non-interactive process such as node --test bug.js | less, I get the error detail scrambled:

TAP version 13
# Subtest: should print the error
not ok 1 - should print the error
  ---
  duration_ms: 0.974875
  failureType: 'hookFailed'
  error: 'failed running after hook'
  code: 'ERR_TEST_FAILURE'
  stack: |-
    TestContext.<anonymous> (/Users/matteo/tmp/bug.js:5:11)
    TestHook.runInAsyncScope (node:async_hooks:206:9)
    TestHook.run (node:internal/test_runner/test:580:25)
    TestHook.run (node:internal/test_runner/test:759:18)
    TestHook.run (node:internal/util:500:12)
    node:internal/test_runner/test:516:20
    async Test.runHook (node:internal/test_runner/test:514:7)
    async after (node:internal/test_runner/test:542:9)
    async Test.run (node:internal/test_runner/test:590:7)
    async startSubtest (node:internal/test_runner/harness:204:3)
  ...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 43.341875

This shows specifically during CI runs, where the pretty reporter is not engaged.

@mcollina mcollina added confirmed-bug Issues with confirmed bugs. test_runner Issues and PRs related to the test runner subsystem. labels Jul 27, 2023
@mcollina mcollina changed the title test: wrong unwrapping of errors in after() when using the --test flag test_runner: wrong unwrapping of errors in after() when using the --test flag Jul 27, 2023
@mcollina mcollina changed the title test_runner: wrong unwrapping of errors in after() when using the --test flag test_runner: incorrect unwrapping of errors in after() when using the --test flag Jul 27, 2023
@mcollina
Copy link
Member Author

Closing. I was using v18.16.1 and in v18.17.0 is fixed.

@mcollina mcollina reopened this Jul 27, 2023
@mcollina
Copy link
Member Author

Actually it's a problem, updating the report.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 27, 2023

This appears to be a bug with the TAP reporter.

@mcollina mcollina changed the title test_runner: incorrect unwrapping of errors in after() when using the --test flag test_runner: incorrect unwrapping of errors in after() when using the tap reporter Jul 27, 2023
@cjihrig
Copy link
Contributor

cjihrig commented Jul 27, 2023

This seems to fix it:

diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js
index 4aec4ba072..e22c647669 100644
--- a/lib/internal/test_runner/reporter/tap.js
+++ b/lib/internal/test_runner/reporter/tap.js
@@ -198,15 +198,14 @@ function jsToYaml(indent, name, value, seen) {
       errStack = cause?.stack ?? errStack;
       errCode = cause?.code ?? errCode;
       errName = cause?.name ?? errName;
+      errMsg = cause?.message ?? errMsg;
+
       if (isAssertionLike(cause)) {
         errExpected = cause.expected;
         errActual = cause.actual;
         errOperator = cause.operator ?? errOperator;
         errIsAssertion = true;
       }
-      if (failureType === kTestCodeFailure) {
-        errMsg = cause?.message ?? errMsg;
-      }
     }
 
     result += jsToYaml(indent, 'error', errMsg, seen);

cjihrig added a commit to cjihrig/node that referenced this issue Jul 27, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
@cjihrig
Copy link
Contributor

cjihrig commented Jul 27, 2023

Proposed fix in #48942

nodejs-github-bot pushed a commit that referenced this issue Jul 29, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: #48941
PR-URL: #48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
pluris pushed a commit to pluris/node that referenced this issue Aug 6, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
pluris pushed a commit to pluris/node that referenced this issue Aug 7, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Ceres6 pushed a commit to Ceres6/node that referenced this issue Aug 14, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this issue Aug 14, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this issue Aug 15, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: #48941
PR-URL: #48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit to RafaelGSS/node that referenced this issue Aug 15, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs#48941
PR-URL: nodejs#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
RafaelGSS pushed a commit that referenced this issue Aug 17, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: #48941
PR-URL: #48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
targos pushed a commit that referenced this issue Nov 27, 2023
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: #48941
PR-URL: #48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs/node#48941
PR-URL: nodejs/node#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
sercher added a commit to sercher/graaljs that referenced this issue Apr 25, 2024
The TAP reporter unwraps errors that come from user code. It
was not properly unwrapping the error message when the failure
originated from a test hook. This lead to difficult to debug
errors when TAP output was used. This commit updates the TAP
reporter to properly unwrap the error message.

Fixes: nodejs/node#48941
PR-URL: nodejs/node#48942
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants