Skip to content

Commit e70711e

Browse files
cjihrigRafaelGSS
authored andcommittedAug 21, 2024
test_runner: report failures in filtered suites
This commit updates the test runner's filter logic to handle test suite failures during the build phase. Prior to this commit, these suites were silently filtered. PR-URL: #54387 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 9f115ba commit e70711e

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed
 

‎lib/internal/test_runner/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1181,15 +1181,15 @@ class Suite extends Test {
11811181
);
11821182
} catch (err) {
11831183
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
1184-
1185-
this.buildPhaseFinished = true;
1184+
this.postBuild();
11861185
}
11871186
this.fn = noop;
11881187
}
11891188

11901189
postBuild() {
11911190
this.buildPhaseFinished = true;
1192-
if (this.filtered && this.filteredSubtestCount !== this.subtests.length) {
1191+
if (this.filtered &&
1192+
(this.filteredSubtestCount !== this.subtests.length || this.error)) {
11931193
// A suite can transition from filtered to unfiltered based on the
11941194
// tests that it contains - in case of children matching patterns.
11951195
this.filtered = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Flags: --test-name-pattern=enabled
2+
'use strict';
3+
const common = require('../../../common');
4+
const { suite, test } = require('node:test');
5+
6+
suite('suite 1', () => {
7+
throw new Error('boom 1');
8+
test('enabled - should not run', common.mustNotCall());
9+
});
10+
11+
suite('suite 2', () => {
12+
test('enabled - should get cancelled', common.mustNotCall());
13+
throw new Error('boom 1');
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
TAP version 13
2+
# Subtest: suite 1
3+
not ok 1 - suite 1
4+
---
5+
duration_ms: *
6+
type: 'suite'
7+
location: '/test/fixtures/test-runner/output/filtered-suite-throws.js:(LINE):1'
8+
failureType: 'testCodeFailure'
9+
error: 'boom 1'
10+
code: 'ERR_TEST_FAILURE'
11+
stack: |-
12+
*
13+
*
14+
*
15+
*
16+
*
17+
*
18+
*
19+
*
20+
*
21+
*
22+
...
23+
# Subtest: suite 2
24+
# Subtest: enabled - should get cancelled
25+
not ok 1 - enabled - should get cancelled
26+
---
27+
duration_ms: *
28+
location: '/test/fixtures/test-runner/output/filtered-suite-throws.js:(LINE):3'
29+
failureType: 'cancelledByParent'
30+
error: 'test did not finish before its parent and was cancelled'
31+
code: 'ERR_TEST_FAILURE'
32+
...
33+
1..1
34+
not ok 2 - suite 2
35+
---
36+
duration_ms: *
37+
type: 'suite'
38+
location: '/test/fixtures/test-runner/output/filtered-suite-throws.js:(LINE):1'
39+
failureType: 'testCodeFailure'
40+
error: 'boom 1'
41+
code: 'ERR_TEST_FAILURE'
42+
stack: |-
43+
*
44+
*
45+
*
46+
*
47+
*
48+
*
49+
*
50+
*
51+
*
52+
*
53+
...
54+
1..2
55+
# tests 1
56+
# suites 2
57+
# pass 0
58+
# fail 0
59+
# cancelled 1
60+
# skipped 0
61+
# todo 0
62+
# duration_ms *

‎test/parallel/test-runner-output.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const tests = [
101101
{ name: 'test-runner/output/eval_dot.js', transform: specTransform },
102102
{ name: 'test-runner/output/eval_spec.js', transform: specTransform },
103103
{ name: 'test-runner/output/eval_tap.js' },
104+
{ name: 'test-runner/output/filtered-suite-throws.js' },
104105
{ name: 'test-runner/output/hooks.js' },
105106
{ name: 'test-runner/output/hooks_spec_reporter.js', transform: specTransform },
106107
{ name: 'test-runner/output/skip-each-hooks.js', transform: specTransform },

0 commit comments

Comments
 (0)