Skip to content

Commit 29b2317

Browse files
authored
test_runner: abort unfinished tests on async error
This commit updates the test runner's uncaughtException handler to abort tests instead of assuming they finished running. Fixes: #51381 PR-URL: #51996 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b241a1d commit 29b2317

10 files changed

+60
-18
lines changed

lib/internal/test_runner/harness.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function createProcessEventHandler(eventName, rootTest) {
7474
}
7575

7676
test.fail(new ERR_TEST_FAILURE(err, eventName));
77-
test.postRun();
77+
test.abortController.abort();
7878
};
7979
}
8080

test/fixtures/test-runner/output/describe_it.snapshot

+1-3
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ not ok 50 - custom inspect symbol that throws fail
494494
*
495495
*
496496
*
497+
async Promise.all (index 0)
497498
*
498499
*
499-
*
500-
async Promise.all (index 0)
501500
...
502501
1..2
503502
not ok 51 - subtest sync throw fails
@@ -628,7 +627,6 @@ not ok 54 - timeouts
628627
code: 'ERR_TEST_FAILURE'
629628
stack: |-
630629
*
631-
*
632630
...
633631
1..2
634632
not ok 55 - successful thenable

test/fixtures/test-runner/output/junit_reporter.snapshot

-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second
372372
*
373373
*
374374
*
375-
*
376-
*
377375
}
378376
</failure>
379377
</testcase>

test/fixtures/test-runner/output/output.snapshot

-2
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,6 @@ not ok 51 - custom inspect symbol that throws fail
552552
*
553553
*
554554
*
555-
*
556-
*
557555
...
558556
1..2
559557
not ok 52 - subtest sync throw fails

test/fixtures/test-runner/output/output_cli.snapshot

-2
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,6 @@ not ok 51 - custom inspect symbol that throws fail
552552
*
553553
*
554554
*
555-
*
556-
*
557555
...
558556
1..2
559557
not ok 52 - subtest sync throw fails

test/fixtures/test-runner/output/spec_reporter.snapshot

-4
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@
229229
*
230230
*
231231
*
232-
*
233-
*
234232

235233
subtest sync throw fails (*ms)
236234

@@ -515,8 +513,6 @@
515513
*
516514
*
517515
*
518-
*
519-
*
520516

521517
*
522518
timed out async test (*ms)

test/fixtures/test-runner/output/spec_reporter_cli.snapshot

-4
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@
229229
*
230230
*
231231
*
232-
*
233-
*
234232

235233
subtest sync throw fails (*ms)
236234

@@ -515,8 +513,6 @@
515513
*
516514
*
517515
*
518-
*
519-
*
520516

521517
*
522518
timed out async test (*ms)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const { describe, it } = require('node:test');
3+
4+
describe('unfinished suite with asynchronous error', () => {
5+
it('uses callback', (t, done) => {
6+
setImmediate(() => {
7+
throw new Error('callback test does not complete');
8+
});
9+
});
10+
11+
it('should pass 1');
12+
});
13+
14+
it('should pass 2');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
TAP version 13
2+
# Subtest: unfinished suite with asynchronous error
3+
# Subtest: uses callback
4+
not ok 1 - uses callback
5+
---
6+
duration_ms: *
7+
location: '/test/fixtures/test-runner/output/unfinished-suite-async-error.js:(LINE):3'
8+
failureType: 'uncaughtException'
9+
error: 'callback test does not complete'
10+
code: 'ERR_TEST_FAILURE'
11+
stack: |-
12+
*
13+
*
14+
...
15+
# Subtest: should pass 1
16+
ok 2 - should pass 1
17+
---
18+
duration_ms: *
19+
...
20+
1..2
21+
not ok 1 - unfinished suite with asynchronous error
22+
---
23+
duration_ms: *
24+
type: 'suite'
25+
location: '/test/fixtures/test-runner/output/unfinished-suite-async-error.js:(LINE):1'
26+
failureType: 'subtestsFailed'
27+
error: '1 subtest failed'
28+
code: 'ERR_TEST_FAILURE'
29+
...
30+
# Subtest: should pass 2
31+
ok 2 - should pass 2
32+
---
33+
duration_ms: *
34+
...
35+
1..2
36+
# tests 3
37+
# suites 1
38+
# pass 2
39+
# fail 1
40+
# cancelled 0
41+
# skipped 0
42+
# todo 0
43+
# duration_ms *

test/parallel/test-runner-output.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const tests = [
112112
{ name: 'test-runner/output/output_cli.js' },
113113
{ name: 'test-runner/output/name_pattern.js' },
114114
{ name: 'test-runner/output/name_pattern_with_only.js' },
115+
{ name: 'test-runner/output/unfinished-suite-async-error.js' },
115116
{ name: 'test-runner/output/unresolved_promise.js' },
116117
{ name: 'test-runner/output/default_output.js', transform: specTransform, tty: true },
117118
{ name: 'test-runner/output/arbitrary-output.js' },

0 commit comments

Comments
 (0)