Skip to content

Commit b5c7e64

Browse files
pmarchinitargos
authored andcommitted
test_runner: correctly filter --experimental-config-file
PR-URL: #58833 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 57c69ac commit b5c7e64

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

lib/internal/test_runner/runner.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ const kFilterArgs = [
103103
'--experimental-test-coverage',
104104
'--watch',
105105
'--experimental-default-config-file',
106+
];
107+
const kFilterArgValues = [
108+
'--test-reporter',
109+
'--test-reporter-destination',
106110
'--experimental-config-file',
107111
];
108-
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
109112
const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
110113

111114
const kCanceledTests = new SafeSet()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from 'node:test';
2+
import { strictEqual } from 'node:assert';
3+
import internal from 'internal/options';
4+
5+
test('it should not receive --experimental-config-file option', () => {
6+
const optionValue = internal.getOptionValue("--experimental-config-file");
7+
strictEqual(optionValue, '');
8+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"testRunner": {
3+
"experimental-test-coverage": true
4+
}
5+
}

test/parallel/test-runner-cli.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,52 @@ for (const isolation of ['none', 'process']) {
429429
assert.strictEqual(child.status, 0);
430430
assert.strictEqual(child.signal, null);
431431
}
432+
433+
{
434+
// Should not propagate --experimental-config-file option to sub test in isolation process
435+
const fixturePath = join(testFixtures, 'options-propagation');
436+
const args = [
437+
'--test-reporter=tap',
438+
'--no-warnings',
439+
`--experimental-config-file=node.config.json`,
440+
'--expose-internals',
441+
'--test',
442+
];
443+
const child = spawnSync(process.execPath, args, { cwd: fixturePath });
444+
445+
assert.strictEqual(child.stderr.toString(), '');
446+
const stdout = child.stdout.toString();
447+
448+
assert.match(stdout, /tests 1/);
449+
assert.match(stdout, /suites 0/);
450+
assert.match(stdout, /pass 1/);
451+
assert.match(stdout, /fail 0/);
452+
assert.match(stdout, /cancelled 0/);
453+
assert.match(stdout, /skipped 0/);
454+
assert.match(stdout, /todo 0/);
455+
456+
457+
assert.strictEqual(child.status, 0);
458+
}
459+
460+
{
461+
if (process.features.inspector) {
462+
// https://github.com/nodejs/node/issues/58828
463+
// Should not print report twice when --experimental-test-coverage is set via config file
464+
const fixturePath = join(testFixtures, 'options-propagation');
465+
const args = [
466+
'--test-reporter=tap',
467+
'--no-warnings',
468+
`--experimental-config-file=node.config.json`,
469+
'--expose-internals',
470+
'--test',
471+
];
472+
473+
const child = spawnSync(process.execPath, args, { cwd: fixturePath });
474+
const stdout = child.stdout.toString();
475+
476+
const coverageReportMatches = stdout.match(/# start of coverage report/g);
477+
assert.strictEqual(coverageReportMatches?.length, 1);
478+
assert.strictEqual(child.stderr.toString(), '');
479+
}
480+
}

0 commit comments

Comments
 (0)