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 run with watch node --test --watch swallows errors in before, after blocks #50355

Closed
chrishiestand opened this issue Oct 24, 2023 · 1 comment · Fixed by #50361
Closed
Labels
test_runner Issues and PRs related to the test runner subsystem.

Comments

@chrishiestand
Copy link

chrishiestand commented Oct 24, 2023

Version

v20.8.1

Platform

Darwin adonai 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000 x86_64

Subsystem

No response

What steps will reproduce the bug?

  1. Save this test to a file, e.g. issue.mjs
import { describe, before, it } from 'node:test';

describe('Testy test', () => {
    before(() => {
        throw new Error('This error is not output');
    });

    it('test', () => {
        console.log('test pass');
    });
});
  1. Run the test runner in watch mode: node --test --watch issue.mjs

How often does it reproduce? Is there a required condition?

reproduces every time

What is the expected behavior? Why is that the expected behavior?

I expect to see the error and stacktrace in the output. If you do not run the test in watch mode, the error is not swallowed and the output looks like:

▶ Testy test
  ✖ test
    'test did not finish before its parent and was cancelled'

▶ Testy test (1.376667ms)

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

✖ failing tests:

test at file:/tmp/issue.mjs:8:5
✖ test
  'test did not finish before its parent and was cancelled'

test at file:/tmp/issue.mjs:3:1
✖ Testy test (1.376667ms)
  Error: This error is not output
      at SuiteContext.<anonymous> (file:///tmp/issue.mjs:5:15)
      at TestHook.runInAsyncScope (node:async_hooks:206:9)
      at TestHook.run (node:internal/test_runner/test:631:25)
      at TestHook.run (node:internal/test_runner/test:856:18)
      at TestHook.run (node:internal/util:531:12)
      at node:internal/test_runner/test:565:20
      at async Suite.runHook (node:internal/test_runner/test:563:7)
      at async Suite.run (node:internal/test_runner/test:942:7)
      at async startSubtest (node:internal/test_runner/harness:208:3)

What do you see instead?

I get output (notice no exception or stack trace):

▶ Testy test
  ✖ test
    'test did not finish before its parent and was cancelled'

▶ Testy test (1.341125ms)

Additional information

If the Error is thrown in it, describe, beforeEach, or afterEach it does show as expected in output. The problem seems to be confined to before and after blocks.

@MoLow MoLow added the test_runner Issues and PRs related to the test runner subsystem. label Oct 24, 2023
@chrishiestand
Copy link
Author

Thanks @MoLow and the rest of the team! This is some impressive development velocity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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