Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,19 @@ function run(options = kEmptyObject) {
cwd,
globalSetupPath,
};

if (isolation === 'none') {
if (testNamePatterns != null) {
globalOptions.testNamePatterns = testNamePatterns;
}
if (testSkipPatterns != null) {
globalOptions.testSkipPatterns = testSkipPatterns;
}
if (only != null) {
globalOptions.only = only;
}
}

const root = createTestTree(rootTestOptions, globalOptions);
let testFiles = files ?? createTestFileList(globPatterns, cwd);
const { isTestRunner } = globalOptions;
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/test-runner/test-runner-isolation-none.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { run } from 'node:test';
import { tap } from 'node:test/reporters';
import { parseArgs } from 'node:util';

const {
values,
} = parseArgs({
args: process.argv.slice(2),
options: {
file: { type: 'string' },
only: { type: 'boolean' },
'name-pattern': { type: 'string' },
'skip-pattern': { type: 'string' },
},
});

const opts = {
isolation: 'none',
files: [values.file],
};

if (values.only) {
opts.only = true;
}
if (values['name-pattern']) {
opts.testNamePatterns = [new RegExp(values['name-pattern'])];
}
if (values['skip-pattern']) {
opts.testSkipPatterns = [new RegExp(values['skip-pattern'])];
}

run(opts).compose(tap).pipe(process.stdout);
42 changes: 42 additions & 0 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,48 @@ describe('forceExit', () => {
});
});

describe('with isolation="none"', () => {
const isolationNoneFixture = fixtures.path('test-runner', 'test-runner-isolation-none.mjs');

it('should pass only to children', async () => {
const child = await common.spawnPromisified(process.execPath, [
isolationNoneFixture,
'--file', join(testFixtures, 'test_only.js'),
'--only',
]);

assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
assert.match(child.stdout, /ok 1 - this should be executed/);
assert.match(child.stdout, /# tests 1/);
});

it('should skip tests not matching testNamePatterns - RegExp', async () => {
const child = await common.spawnPromisified(process.execPath, [
isolationNoneFixture,
'--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'),
'--name-pattern', 'executed',
]);

assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
assert.match(child.stdout, /ok 1 - this should be executed/);
assert.match(child.stdout, /# tests 1/);
});

it('should skip tests matching testSkipPatterns - RegExp', async () => {
const child = await common.spawnPromisified(process.execPath, [
isolationNoneFixture,
'--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'),
'--skip-pattern', 'skipped',
]);

assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
assert.match(child.stdout, /ok 1 - this should be executed/);
assert.match(child.stdout, /# tests 1/);
});
});

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