Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 920804d

Browse filesBrowse files
fossamagnaRafaelGSS
authored andcommitted
test_runner: avoid swallowing of asynchronously thrown errors
Fixes: #44612 PR-URL: #45264 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 4b71db1 commit 920804d
Copy full SHA for 920804d

File tree

Expand file treeCollapse file tree

6 files changed

+45
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+45
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ top level of the file's TAP output.
272272

273273
The second `setImmediate()` creates an `uncaughtException` event.
274274
`uncaughtException` and `unhandledRejection` events originating from a completed
275-
test are handled by the `test` module and reported as diagnostic warnings in
276-
the top level of the file's TAP output.
275+
test are marked as failed by the `test` module and reported as diagnostic
276+
warnings in the top level of the file's TAP output.
277277

278278
```js
279279
test('a test that creates asynchronous activity', (t) => {
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function createProcessEventHandler(eventName, rootTest) {
4646
`triggered an ${eventName} event.`;
4747

4848
rootTest.diagnostic(msg);
49+
process.exitCode = kGenericUserError;
4950
return;
5051
}
5152

Collapse file

‎test/es-module/test-esm-repl-imports.js‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-repl-imports.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { describe, it } = require('node:test');
99

1010

1111
describe('ESM: REPL runs', { concurrency: true }, () => {
12-
it((context, done) => {
12+
it((done) => {
1313
const child = spawn(execPath, [
1414
'--interactive',
1515
], {
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from 'node:test';
2+
3+
test('extraneous async activity test', () => {
4+
setImmediate(() => { throw new Error(); });
5+
});
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from 'node:test';
2+
3+
test('extraneous async activity test', () => {
4+
setTimeout(() => { throw new Error(); }, 100);
5+
});
Collapse file
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
require('../common');
3+
const fixtures = require('../common/fixtures');
4+
const assert = require('assert');
5+
const { spawnSync } = require('child_process');
6+
7+
{
8+
const child = spawnSync(process.execPath, [
9+
'--test',
10+
fixtures.path('test-runner', 'extraneous_set_immediate_async.mjs'),
11+
]);
12+
const stdout = child.stdout.toString();
13+
assert.match(stdout, /^# pass 0$/m);
14+
assert.match(stdout, /^# fail 1$/m);
15+
assert.match(stdout, /^# cancelled 0$/m);
16+
assert.strictEqual(child.status, 1);
17+
assert.strictEqual(child.signal, null);
18+
}
19+
20+
{
21+
const child = spawnSync(process.execPath, [
22+
'--test',
23+
fixtures.path('test-runner', 'extraneous_set_timeout_async.mjs'),
24+
]);
25+
const stdout = child.stdout.toString();
26+
assert.match(stdout, /^# pass 0$/m);
27+
assert.match(stdout, /^# fail 1$/m);
28+
assert.match(stdout, /^# cancelled 0$/m);
29+
assert.strictEqual(child.status, 1);
30+
assert.strictEqual(child.signal, null);
31+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.