Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMURAKAMI Masahiko <fossamagna2@gmail.com>2022-11-07 15:02:56 +0300
committerGitHub <noreply@github.com>2022-11-07 15:02:56 +0300
commit06603c44a5b0e92b1a3591ace467ce9770bf9658 (patch)
tree5482925276d28e574d4a48352d097f96a84cbb91
parentb13738a55830708c49f277d1d8ee7a6dc0594308 (diff)
test_runner: avoid swallowing of asynchronously thrown errors
Fixes: https://github.com/nodejs/node/issues/44612 PR-URL: https://github.com/nodejs/node/pull/45264 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--doc/api/test.md4
-rw-r--r--lib/internal/test_runner/harness.js1
-rw-r--r--test/es-module/test-esm-repl-imports.js2
-rw-r--r--test/fixtures/test-runner/extraneous_set_immediate_async.mjs5
-rw-r--r--test/fixtures/test-runner/extraneous_set_timeout_async.mjs5
-rw-r--r--test/parallel/test-runner-extraneous-async-activity.js31
6 files changed, 45 insertions, 3 deletions
diff --git a/doc/api/test.md b/doc/api/test.md
index 69e37025bee..8d2fa871ce6 100644
--- a/doc/api/test.md
+++ b/doc/api/test.md
@@ -272,8 +272,8 @@ top level of the file's TAP output.
The second `setImmediate()` creates an `uncaughtException` event.
`uncaughtException` and `unhandledRejection` events originating from a completed
-test are handled by the `test` module and reported as diagnostic warnings in
-the top level of the file's TAP output.
+test are marked as failed by the `test` module and reported as diagnostic
+warnings in the top level of the file's TAP output.
```js
test('a test that creates asynchronous activity', (t) => {
diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js
index 99465ddfedd..0a6be080e8b 100644
--- a/lib/internal/test_runner/harness.js
+++ b/lib/internal/test_runner/harness.js
@@ -46,6 +46,7 @@ function createProcessEventHandler(eventName, rootTest) {
`triggered an ${eventName} event.`;
rootTest.diagnostic(msg);
+ process.exitCode = kGenericUserError;
return;
}
diff --git a/test/es-module/test-esm-repl-imports.js b/test/es-module/test-esm-repl-imports.js
index 9547824756f..a6224a54cee 100644
--- a/test/es-module/test-esm-repl-imports.js
+++ b/test/es-module/test-esm-repl-imports.js
@@ -9,7 +9,7 @@ const { describe, it } = require('node:test');
describe('ESM: REPL runs', { concurrency: true }, () => {
- it((context, done) => {
+ it((done) => {
const child = spawn(execPath, [
'--interactive',
], {
diff --git a/test/fixtures/test-runner/extraneous_set_immediate_async.mjs b/test/fixtures/test-runner/extraneous_set_immediate_async.mjs
new file mode 100644
index 00000000000..cf001fb42be
--- /dev/null
+++ b/test/fixtures/test-runner/extraneous_set_immediate_async.mjs
@@ -0,0 +1,5 @@
+import test from 'node:test';
+
+test('extraneous async activity test', () => {
+ setImmediate(() => { throw new Error(); });
+});
diff --git a/test/fixtures/test-runner/extraneous_set_timeout_async.mjs b/test/fixtures/test-runner/extraneous_set_timeout_async.mjs
new file mode 100644
index 00000000000..be4aaa80edc
--- /dev/null
+++ b/test/fixtures/test-runner/extraneous_set_timeout_async.mjs
@@ -0,0 +1,5 @@
+import test from 'node:test';
+
+test('extraneous async activity test', () => {
+ setTimeout(() => { throw new Error(); }, 100);
+});
diff --git a/test/parallel/test-runner-extraneous-async-activity.js b/test/parallel/test-runner-extraneous-async-activity.js
new file mode 100644
index 00000000000..d0fbf5fd2b4
--- /dev/null
+++ b/test/parallel/test-runner-extraneous-async-activity.js
@@ -0,0 +1,31 @@
+'use strict';
+require('../common');
+const fixtures = require('../common/fixtures');
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+
+{
+ const child = spawnSync(process.execPath, [
+ '--test',
+ fixtures.path('test-runner', 'extraneous_set_immediate_async.mjs'),
+ ]);
+ const stdout = child.stdout.toString();
+ assert.match(stdout, /^# pass 0$/m);
+ assert.match(stdout, /^# fail 1$/m);
+ assert.match(stdout, /^# cancelled 0$/m);
+ assert.strictEqual(child.status, 1);
+ assert.strictEqual(child.signal, null);
+}
+
+{
+ const child = spawnSync(process.execPath, [
+ '--test',
+ fixtures.path('test-runner', 'extraneous_set_timeout_async.mjs'),
+ ]);
+ const stdout = child.stdout.toString();
+ assert.match(stdout, /^# pass 0$/m);
+ assert.match(stdout, /^# fail 1$/m);
+ assert.match(stdout, /^# cancelled 0$/m);
+ assert.strictEqual(child.status, 1);
+ assert.strictEqual(child.signal, null);
+}