Skip to content

Commit

Permalink
test_runner: abort unfinished tests on async error
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and marco-ippolito committed May 2, 2024
1 parent 18838f2 commit a4cbb61
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function createProcessEventHandler(eventName, rootTest) {
}

test.fail(new ERR_TEST_FAILURE(err, eventName));
test.postRun();
test.abortController.abort();
};
}

Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/test-runner/output/describe_it.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,9 @@ not ok 50 - custom inspect symbol that throws fail
*
*
*
async Promise.all (index 0)
*
*
*
async Promise.all (index 0)
...
1..2
not ok 51 - subtest sync throw fails
Expand Down Expand Up @@ -628,7 +627,6 @@ not ok 54 - timeouts
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
...
1..2
not ok 55 - successful thenable
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/test-runner/output/junit_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second
*
*
*
*
*
}
</failure>
</testcase>
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/test-runner/output/output.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,6 @@ not ok 51 - custom inspect symbol that throws fail
*
*
*
*
*
...
1..2
not ok 52 - subtest sync throw fails
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/test-runner/output/output_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,6 @@ not ok 51 - custom inspect symbol that throws fail
*
*
*
*
*
...
1..2
not ok 52 - subtest sync throw fails
Expand Down
4 changes: 0 additions & 4 deletions test/fixtures/test-runner/output/spec_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@
*
*
*
*
*

subtest sync throw fails (*ms)

Expand Down Expand Up @@ -515,8 +513,6 @@
*
*
*
*
*

*
timed out async test (*ms)
Expand Down
4 changes: 0 additions & 4 deletions test/fixtures/test-runner/output/spec_reporter_cli.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@
*
*
*
*
*

subtest sync throw fails (*ms)

Expand Down Expand Up @@ -515,8 +513,6 @@
*
*
*
*
*

*
timed out async test (*ms)
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/test-runner/output/unfinished-suite-async-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
const { describe, it } = require('node:test');

describe('unfinished suite with asynchronous error', () => {
it('uses callback', (t, done) => {
setImmediate(() => {
throw new Error('callback test does not complete');
});
});

it('should pass 1');
});

it('should pass 2');
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
TAP version 13
# Subtest: unfinished suite with asynchronous error
# Subtest: uses callback
not ok 1 - uses callback
---
duration_ms: *
location: '/test/fixtures/test-runner/output/unfinished-suite-async-error.js:(LINE):3'
failureType: 'uncaughtException'
error: 'callback test does not complete'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
...
# Subtest: should pass 1
ok 2 - should pass 1
---
duration_ms: *
...
1..2
not ok 1 - unfinished suite with asynchronous error
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/unfinished-suite-async-error.js:(LINE):1'
failureType: 'subtestsFailed'
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
...
# Subtest: should pass 2
ok 2 - should pass 2
---
duration_ms: *
...
1..2
# tests 3
# suites 1
# pass 2
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms *
1 change: 1 addition & 0 deletions test/parallel/test-runner-output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const tests = [
{ name: 'test-runner/output/output_cli.js' },
{ name: 'test-runner/output/name_pattern.js' },
{ name: 'test-runner/output/name_pattern_with_only.js' },
{ name: 'test-runner/output/unfinished-suite-async-error.js' },
{ name: 'test-runner/output/unresolved_promise.js' },
{ name: 'test-runner/output/default_output.js', transform: specTransform, tty: true },
{ name: 'test-runner/output/arbitrary-output.js' },
Expand Down

0 comments on commit a4cbb61

Please sign in to comment.