Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ebe3a4

Browse filesBrowse files
MoLowRafaelGSS
authored andcommitted
test_runner: make --test-name-pattern recursive
PR-URL: #48382 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent f9c0d5a commit 5ebe3a4
Copy full SHA for 5ebe3a4

File tree

Expand file treeCollapse file tree

5 files changed

+124
-31
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+124
-31
lines changed
Open diff view settings
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+16-11Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,11 @@ class Test extends AsyncResource {
246246
this.timeout = timeout;
247247
}
248248

249-
if (testNamePatterns !== null) {
250-
// eslint-disable-next-line no-use-before-define
251-
const match = this instanceof TestHook || ArrayPrototypeSome(
252-
testNamePatterns,
253-
(re) => RegExpPrototypeExec(re, name) !== null,
254-
);
249+
this.name = name;
250+
this.parent = parent;
255251

256-
if (!match) {
257-
skip = 'test name does not match pattern';
258-
}
252+
if (testNamePatterns !== null && !this.matchesTestNamePatterns()) {
253+
skip = 'test name does not match pattern';
259254
}
260255

261256
if (testOnlyFlag && !this.only) {
@@ -276,8 +271,6 @@ class Test extends AsyncResource {
276271
this.fn = fn;
277272
this.harness = null; // Configured on the root test by the test harness.
278273
this.mock = null;
279-
this.name = name;
280-
this.parent = parent;
281274
this.cancelled = false;
282275
this.skipped = !!skip;
283276
this.isTodo = !!todo;
@@ -302,6 +295,11 @@ class Test extends AsyncResource {
302295
}
303296
}
304297

298+
matchesTestNamePatterns() {
299+
return ArrayPrototypeSome(testNamePatterns, (re) => RegExpPrototypeExec(re, this.name) !== null) ||
300+
this.parent?.matchesTestNamePatterns();
301+
}
302+
305303
hasConcurrency() {
306304
return this.concurrency > this.activeSubtests;
307305
}
@@ -750,6 +748,9 @@ class TestHook extends Test {
750748
getRunArgs() {
751749
return this.#args;
752750
}
751+
matchesTestNamePatterns() {
752+
return true;
753+
}
753754
postRun() {
754755
}
755756
}
@@ -759,6 +760,10 @@ class Suite extends Test {
759760
constructor(options) {
760761
super(options);
761762

763+
if (testNamePatterns !== null && !options.skip && !options.todo) {
764+
this.fn = options.fn || this.fn;
765+
this.skipped = false;
766+
}
762767
this.runOnlySubtests = testOnlyFlag;
763768

764769
try {
Collapse file

‎test/fixtures/test-runner/output/name_pattern.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/name_pattern.js
+24-4Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --no-warnings --test-name-pattern=enabled --test-name-pattern=/pattern/i
1+
// Flags: --no-warnings --test-name-pattern=enabled --test-name-pattern=yes --test-name-pattern=/pattern/i
22
'use strict';
33
const common = require('../../../common');
44
const {
@@ -18,7 +18,7 @@ it('top level it enabled', common.mustCall());
1818
it('top level it disabled', common.mustNotCall());
1919
it.skip('top level skipped it disabled', common.mustNotCall());
2020
it.skip('top level skipped it enabled', common.mustNotCall());
21-
describe('top level describe disabled', common.mustNotCall());
21+
describe('top level describe never disabled', common.mustCall());
2222
describe.skip('top level skipped describe disabled', common.mustNotCall());
2323
describe.skip('top level skipped describe enabled', common.mustNotCall());
2424
test('top level runs because name includes PaTtErN', common.mustCall());
@@ -38,10 +38,30 @@ describe('top level describe enabled', () => {
3838
afterEach(common.mustCall(3));
3939
after(common.mustCall());
4040

41-
it('nested it disabled', common.mustNotCall());
41+
it('nested it not disabled', common.mustCall());
4242
it('nested it enabled', common.mustCall());
43-
describe('nested describe disabled', common.mustNotCall());
43+
describe('nested describe not disabled', common.mustCall());
4444
describe('nested describe enabled', common.mustCall(() => {
4545
it('is enabled', common.mustCall());
4646
}));
4747
});
48+
49+
describe('yes', function() {
50+
it('no', () => {});
51+
it('yes', () => {});
52+
53+
describe('maybe', function() {
54+
it('no', () => {});
55+
it('yes', () => {});
56+
});
57+
});
58+
59+
describe('no', function() {
60+
it('no', () => {});
61+
it('yes', () => {});
62+
63+
describe('maybe', function() {
64+
it('no', () => {});
65+
it('yes', () => {});
66+
});
67+
});
Collapse file

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

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/name_pattern.snapshot
+79-11Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ ok 7 - top level skipped it enabled # SKIP
3434
---
3535
duration_ms: *
3636
...
37-
# Subtest: top level describe disabled
38-
ok 8 - top level describe disabled # SKIP test name does not match pattern
37+
# Subtest: top level describe never disabled
38+
ok 8 - top level describe never disabled
3939
---
4040
duration_ms: *
4141
type: 'suite'
@@ -69,8 +69,8 @@ ok 12 - top level test enabled
6969
duration_ms: *
7070
...
7171
# Subtest: top level describe enabled
72-
# Subtest: nested it disabled
73-
ok 1 - nested it disabled # SKIP test name does not match pattern
72+
# Subtest: nested it not disabled
73+
ok 1 - nested it not disabled
7474
---
7575
duration_ms: *
7676
...
@@ -79,8 +79,8 @@ ok 12 - top level test enabled
7979
---
8080
duration_ms: *
8181
...
82-
# Subtest: nested describe disabled
83-
ok 3 - nested describe disabled # SKIP test name does not match pattern
82+
# Subtest: nested describe not disabled
83+
ok 3 - nested describe not disabled
8484
---
8585
duration_ms: *
8686
type: 'suite'
@@ -103,12 +103,80 @@ ok 13 - top level describe enabled
103103
duration_ms: *
104104
type: 'suite'
105105
...
106-
1..13
107-
# tests 13
108-
# suites 6
109-
# pass 6
106+
# Subtest: yes
107+
# Subtest: no
108+
ok 1 - no
109+
---
110+
duration_ms: *
111+
...
112+
# Subtest: yes
113+
ok 2 - yes
114+
---
115+
duration_ms: *
116+
...
117+
# Subtest: maybe
118+
# Subtest: no
119+
ok 1 - no
120+
---
121+
duration_ms: *
122+
...
123+
# Subtest: yes
124+
ok 2 - yes
125+
---
126+
duration_ms: *
127+
...
128+
1..2
129+
ok 3 - maybe
130+
---
131+
duration_ms: *
132+
type: 'suite'
133+
...
134+
1..3
135+
ok 14 - yes
136+
---
137+
duration_ms: *
138+
type: 'suite'
139+
...
140+
# Subtest: no
141+
# Subtest: no
142+
ok 1 - no # SKIP test name does not match pattern
143+
---
144+
duration_ms: *
145+
...
146+
# Subtest: yes
147+
ok 2 - yes
148+
---
149+
duration_ms: *
150+
...
151+
# Subtest: maybe
152+
# Subtest: no
153+
ok 1 - no # SKIP test name does not match pattern
154+
---
155+
duration_ms: *
156+
...
157+
# Subtest: yes
158+
ok 2 - yes
159+
---
160+
duration_ms: *
161+
...
162+
1..2
163+
ok 3 - maybe
164+
---
165+
duration_ms: *
166+
type: 'suite'
167+
...
168+
1..3
169+
ok 15 - no
170+
---
171+
duration_ms: *
172+
type: 'suite'
173+
...
174+
1..15
175+
# tests 21
176+
# suites 10
177+
# pass 13
110178
# fail 0
111179
# cancelled 0
112-
# skipped 7
180+
# skipped 8
113181
# todo 0
114182
# duration_ms *
Collapse file

‎test/fixtures/test-runner/output/name_pattern_with_only.js‎

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/name_pattern_with_only.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { test } = require('node:test');
55

66
test('enabled and only', { only: true }, common.mustCall(async (t) => {
77
await t.test('enabled', common.mustCall());
8-
await t.test('disabled', common.mustNotCall());
8+
await t.test('disabled but parent not', common.mustCall());
99
}));
1010

1111
test('enabled but not only', common.mustNotCall());
Collapse file

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

Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/name_pattern_with_only.snapshot
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ TAP version 13
55
---
66
duration_ms: *
77
...
8-
# Subtest: disabled
9-
ok 2 - disabled # SKIP test name does not match pattern
8+
# Subtest: disabled but parent not
9+
ok 2 - disabled but parent not
1010
---
1111
duration_ms: *
1212
...
@@ -33,9 +33,9 @@ ok 4 - not only and does not match pattern # SKIP 'only' option not set
3333
1..4
3434
# tests 6
3535
# suites 0
36-
# pass 2
36+
# pass 3
3737
# fail 0
3838
# cancelled 0
39-
# skipped 4
39+
# skipped 3
4040
# todo 0
4141
# duration_ms *

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.