Skip to content

Commit 4c8e03d

Browse files
committed
lib: support testNamePatterns and testSkipPatterns with 'none' isolation
1 parent 813b4e8 commit 4c8e03d

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,17 @@ function run(options = kEmptyObject) {
707707
cwd,
708708
globalSetupPath,
709709
};
710+
711+
if (isolation === 'none') {
712+
if (testNamePatterns && !globalOptions.testNamePatterns) {
713+
globalOptions.testNamePatterns = testNamePatterns
714+
}
715+
716+
if (testSkipPatterns && !globalOptions.testSkipPatterns) {
717+
globalOptions.testSkipPatterns = testSkipPatterns
718+
}
719+
}
720+
710721
const root = createTestTree(rootTestOptions, globalOptions);
711722
let testFiles = files ?? createTestFileList(globPatterns, cwd);
712723
const { isTestRunner } = globalOptions;

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
206206
files: [join(testFixtures, 'default-behavior/test/random.cjs')],
207207
watch: true,
208208
signal: controller.signal,
209-
}).on('data', function({ type }) {
209+
}).on('data', function ({ type }) {
210210
if (type === 'test:watch:drained') {
211211
controller.abort();
212212
}
@@ -650,6 +650,48 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
650650
});
651651
});
652652

653+
describe("with isolation set to 'none'",() => {
654+
it('should skip tests not matching testNamePatterns - string', async () => {
655+
const result = await run({
656+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
657+
testNamePatterns: ['executed'],
658+
isolation: 'none',
659+
})
660+
.compose(tap)
661+
.toArray();
662+
assert.strictEqual(result[2], 'ok 1 - this should be executed\n');
663+
assert.strictEqual(result[4], '1..1\n');
664+
assert.strictEqual(result[5], '# tests 1\n');
665+
});
666+
667+
it('should skip tests not matching testNamePatterns - RegExp', async () => {
668+
const result = await run({
669+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
670+
testNamePatterns: [/executed/],
671+
isolation: 'none',
672+
})
673+
.compose(tap)
674+
.toArray();
675+
assert.strictEqual(result[2], 'ok 1 - this should be executed\n');
676+
assert.strictEqual(result[4], '1..1\n');
677+
assert.strictEqual(result[5], '# tests 1\n');
678+
});
679+
680+
it('should skip tests matching testSkipPatterns', async () => {
681+
const result = await run({
682+
files: [join(testFixtures, 'default-behavior/test/skip_by_name.cjs')],
683+
testSkipPatterns: ['skipped'],
684+
isolation: 'none',
685+
})
686+
.compose(tap)
687+
.toArray();
688+
689+
assert.strictEqual(result[2], 'ok 1 - this should be executed\n');
690+
assert.strictEqual(result[4], '1..1\n');
691+
assert.strictEqual(result[5], '# tests 1\n');
692+
});
693+
});
694+
653695
describe('forceExit', () => {
654696
it('throws for non-boolean values', () => {
655697
[Symbol(), {}, 0, 1, '1', Promise.resolve([])].forEach((forceExit) => {
@@ -668,7 +710,6 @@ describe('forceExit', () => {
668710
});
669711
});
670712

671-
672713
// exitHandler doesn't run until after the tests / after hooks finish.
673714
process.on('exit', () => {
674715
assert.strictEqual(process.listeners('uncaughtException').length, 0);

0 commit comments

Comments
 (0)