GeezerVison is showing github.com — test_runner: use run options with isolation="none" · nodejs/node@be3c8fd
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/runner.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -941,6 +941,18 @@ function run(options = kEmptyObject) { | 941 | 941 | testTagFilters, | 942 | 942 | }; | 943 | 943 |
| | 944 | + if (isolation === 'none') { | | 945 | + if (testNamePatterns != null) { | | 946 | + globalOptions.testNamePatterns = testNamePatterns; | | 947 | + } | | 948 | + if (testSkipPatterns != null) { | | 949 | + globalOptions.testSkipPatterns = testSkipPatterns; | | 950 | + } | | 951 | + if (only != null) { | | 952 | + globalOptions.only = only; | | 953 | + } | | 954 | + } | | 955 | + | 944 | 956 | const root = createTestTree(rootTestOptions, globalOptions); | 945 | 957 | let testFiles = files ?? createTestFileList(globPatterns, cwd); | 946 | 958 | const { isTestRunner } = globalOptions; | |
Collapse file Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-run.mjs +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -872,6 +872,48 @@ describe('forceExit', () => { | 872 | 872 | }); | 873 | 873 | }); | 874 | 874 |
| | 875 | +describe('with isolation="none"', () => { | | 876 | + const isolationNoneFixture = fixtures.path('test-runner', 'test-runner-isolation-none.mjs'); | | 877 | + | | 878 | + it('should pass only to children', async () => { | | 879 | + const child = await common.spawnPromisified(process.execPath, [ | | 880 | + isolationNoneFixture, | | 881 | + '--file', join(testFixtures, 'test_only.js'), | | 882 | + '--only', | | 883 | + ]); | | 884 | + | | 885 | + assert.strictEqual(child.stderr, ''); | | 886 | + assert.strictEqual(child.code, 0); | | 887 | + assert.match(child.stdout, /ok 1 - this should be executed/); | | 888 | + assert.match(child.stdout, /# tests 1/); | | 889 | + }); | | 890 | + | | 891 | + it('should skip tests not matching testNamePatterns - RegExp', async () => { | | 892 | + const child = await common.spawnPromisified(process.execPath, [ | | 893 | + isolationNoneFixture, | | 894 | + '--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'), | | 895 | + '--name-pattern', 'executed', | | 896 | + ]); | | 897 | + | | 898 | + assert.strictEqual(child.stderr, ''); | | 899 | + assert.strictEqual(child.code, 0); | | 900 | + assert.match(child.stdout, /ok 1 - this should be executed/); | | 901 | + assert.match(child.stdout, /# tests 1/); | | 902 | + }); | | 903 | + | | 904 | + it('should skip tests matching testSkipPatterns - RegExp', async () => { | | 905 | + const child = await common.spawnPromisified(process.execPath, [ | | 906 | + isolationNoneFixture, | | 907 | + '--file', join(testFixtures, 'default-behavior/test/skip_by_name.cjs'), | | 908 | + '--skip-pattern', 'skipped', | | 909 | + ]); | | 910 | + | | 911 | + assert.strictEqual(child.stderr, ''); | | 912 | + assert.strictEqual(child.code, 0); | | 913 | + assert.match(child.stdout, /ok 1 - this should be executed/); | | 914 | + assert.match(child.stdout, /# tests 1/); | | 915 | + }); | | 916 | +}); | 875 | 917 |
| 876 | 918 | // exitHandler doesn't run until after the tests / after hooks finish. | 877 | 919 | process.on('exit', () => { | |
|