Skip to content

Commit

Permalink
test_runner: extraneous async activity make a failure
Browse files Browse the repository at this point in the history
  • Loading branch information
fossamagna committed Nov 1, 2022
1 parent a14fc49 commit 01170fa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ 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
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
Expand Down
1 change: 1 addition & 0 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function createProcessEventHandler(eventName, rootTest) {
`triggered an ${eventName} event.`;

rootTest.diagnostic(msg);
process.exitCode = 1;
return;
}

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/test-runner/extraneous_set_immediate_async.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from 'node:test';

test('extraneous async activity test', () => {
setImmediate(() => { throw new Error(); });
});
5 changes: 5 additions & 0 deletions test/fixtures/test-runner/extraneous_set_timeout_async.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from 'node:test';

test('extraneous async activity test', () => {
setTimeout(() => { throw new Error(); }, 100);
});
24 changes: 24 additions & 0 deletions test/parallel/test-runner-extraneous-async-activity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
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);
}

0 comments on commit 01170fa

Please sign in to comment.