Skip to content

Commit 5b60677

Browse files
committed
test_runner: do not name-filter test file wrappers
Since run() applies testNamePatterns and testSkipPatterns to the root test configuration under isolation 'none', the file level test that wraps the single spawned process in watch mode is filtered by name itself. Its name is empty, so any name pattern filtered it out and no test ever ran. The same happens on the CLI with `--test --watch --test-isolation=none --test-name-pattern=...`. Exempt file wrappers from name filtering, as is already done for tag filtering: the patterns are applied to the tests inside of the file by the child process. Refs: nodejs#64359 Refs: nodejs#62269 Signed-off-by: uditDewan <[email protected]>
1 parent c9eed87 commit 5b60677

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ class FileTest extends Test {
311311
return false;
312312
}
313313

314+
willBeFilteredByName() {
315+
// A FileTest represents a test file, not a named test. Name filters are
316+
// applied to the tests inside of the file by the child process.
317+
return false;
318+
}
319+
314320
#skipReporting() {
315321
return this.#reportedChildren > 0 && (!this.error || this.error.failureType === kSubtestsFailed);
316322
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,28 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
213213
assert.strictEqual(result[5], '# tests 1\n');
214214
});
215215

216+
it('should run tests with testNamePatterns in watch mode with isolation \'none\'', async () => {
217+
// The name filters must not be applied to the file level test that wraps
218+
// the spawned process. Without this, no test ever runs.
219+
const controller = new AbortController();
220+
const passes = [];
221+
const stream = run({
222+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
223+
watch: true,
224+
isolation: 'none',
225+
signal: controller.signal,
226+
testNamePatterns: [/executed/],
227+
});
228+
stream.on('test:pass', (event) => {
229+
passes.push(event.name);
230+
controller.abort();
231+
});
232+
// eslint-disable-next-line no-unused-vars
233+
for await (const _ of stream);
234+
assert.ok(passes.length > 0);
235+
assert.ok(!passes.includes('this should be skipped'));
236+
});
237+
216238
it('should pass only to children', async () => {
217239
const result = await run({
218240
files: [join(testFixtures, 'test_only.js')],

0 commit comments

Comments
 (0)