Skip to content

Commit c4f6220

Browse files
committed
test_runner: use run options with isolation="none"
When using run() programatically with isolation="none", testNamePatterns, testSkipPattersn, and only were ignored. This combination of options only worked when set via CLI flags, because parseCommandLine() is still used to seed globalOptions. Fixes: nodejs#57399 Signed-off-by: Sylvester Keil <[email protected]>
1 parent 676e9da commit c4f6220

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,18 @@ function run(options = kEmptyObject) {
880880
testTagFilters,
881881
};
882882

883+
if (isolation === 'none') {
884+
if (testNamePatterns != null) {
885+
globalOptions.testNamePatterns = testNamePatterns;
886+
}
887+
if (testSkipPatterns != null) {
888+
globalOptions.testSkipPatterns = testSkipPatterns;
889+
}
890+
if (only != null) {
891+
globalOptions.only = only;
892+
}
893+
}
894+
883895
const root = createTestTree(rootTestOptions, globalOptions);
884896
let testFiles = files ?? createTestFileList(globPatterns, cwd);
885897
const { isTestRunner } = globalOptions;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { run } from 'node:test';
2+
import { tap } from 'node:test/reporters';
3+
import { parseArgs } from 'node:util';
4+
5+
const {
6+
values,
7+
} = parseArgs({
8+
args: process.argv.slice(2),
9+
options: {
10+
file: { type: 'string' },
11+
only: { type: 'boolean' },
12+
'name-pattern': { type: 'string' },
13+
'skip-pattern': { type: 'string' },
14+
},
15+
});
16+
17+
const opts = {
18+
isolation: 'none',
19+
files: [values.file],
20+
};
21+
22+
if (values.only) {
23+
opts.only = true;
24+
}
25+
if (values['name-pattern']) {
26+
opts.testNamePatterns = [new RegExp(values['name-pattern'])];
27+
}
28+
if (values['skip-pattern']) {
29+
opts.testSkipPatterns = [new RegExp(values['skip-pattern'])];
30+
}
31+
32+
run(opts).compose(tap).pipe(process.stdout);

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,48 @@ describe('forceExit', () => {
862862
});
863863
});
864864

865+
describe('with isolation="none"', () => {
866+
const isolationNoneFixture = fixtures.path('test-runner', 'test-runner-isolation-none.mjs');
867+
868+
it('should pass only to children', async () => {
869+
const child = await common.spawnPromisified(process.execPath, [
870+
isolationNoneFixture,
871+
'--file', join(testFixtures, 'test_only.js'),
872+
'--only',
873+
]);
874+
875+
assert.strictEqual(child.stderr, '');
876+
assert.strictEqual(child.code, 0);
877+
assert.match(child.stdout, /ok 1 - this should be executed/);
878+
assert.match(child.stdout, /# tests 1/);
879+
});
880+
881+
it('should skip tests not matching testNamePatterns - RegExp', async () => {
882+
const child = await common.spawnPromisified(process.execPath, [
883+
isolationNoneFixture,
884+
'--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'),
885+
'--name-pattern', 'executed',
886+
]);
887+
888+
assert.strictEqual(child.stderr, '');
889+
assert.strictEqual(child.code, 0);
890+
assert.match(child.stdout, /ok 1 - this should be executed/);
891+
assert.match(child.stdout, /# tests 1/);
892+
});
893+
894+
it('should skip tests matching testSkipPatterns - RegExp', async () => {
895+
const child = await common.spawnPromisified(process.execPath, [
896+
isolationNoneFixture,
897+
'--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'),
898+
'--skip-pattern', 'skipped',
899+
]);
900+
901+
assert.strictEqual(child.stderr, '');
902+
assert.strictEqual(child.code, 0);
903+
assert.match(child.stdout, /ok 1 - this should be executed/);
904+
assert.match(child.stdout, /# tests 1/);
905+
});
906+
});
865907

866908
// exitHandler doesn't run until after the tests / after hooks finish.
867909
process.on('exit', () => {

0 commit comments

Comments
 (0)