Skip to content

Commit 63563f8

Browse files
cjihrigjuanarbol
authored andcommitted
doc,lib,src,test: rename --test-coverage
Add experimental to the name as requested during review. PR-URL: #46017 Backport-PR-URL: #46839 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent 28a775b commit 63563f8

File tree

8 files changed

+42
-35
lines changed

8 files changed

+42
-35
lines changed

doc/api/cli.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ the ability to import a directory that has an index file.
440440

441441
See [customizing ESM specifier resolution][] for example usage.
442442

443+
### `--experimental-test-coverage`
444+
445+
<!-- YAML
446+
added: REPLACEME
447+
-->
448+
449+
When used in conjunction with the `node:test` module, a code coverage report is
450+
generated as part of the test runner output. If no tests are run, a coverage
451+
report is not generated. See the documentation on
452+
[collecting code coverage from tests][] for more details.
453+
443454
### `--experimental-vm-modules`
444455

445456
<!-- YAML
@@ -1209,17 +1220,6 @@ Starts the Node.js command line test runner. This flag cannot be combined with
12091220
See the documentation on [running tests from the command line][]
12101221
for more details.
12111222

1212-
### `--test-coverage`
1213-
1214-
<!-- YAML
1215-
added: REPLACEME
1216-
-->
1217-
1218-
When used in conjunction with the `node:test` module, a code coverage report is
1219-
generated as part of the test runner output. If no tests are run, a coverage
1220-
report is not generated. See the documentation on
1221-
[collecting code coverage from tests][] for more details.
1222-
12231223
### `--test-name-pattern`
12241224

12251225
<!-- YAML

doc/api/test.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,14 @@ internally.
370370

371371
## Collecting code coverage
372372

373-
When Node.js is started with the [`--test-coverage`][] command-line flag, code
374-
coverage is collected and statistics are reported once all tests have completed.
375-
If the [`NODE_V8_COVERAGE`][] environment variable is used to specify a
376-
code coverage directory, the generated V8 coverage files are written to that
377-
directory. Node.js core modules and files within `node_modules/` directories
378-
are not included in the coverage report. If coverage is enabled, the coverage
379-
report is sent to any [test reporters][] via the `'test:coverage'` event.
373+
When Node.js is started with the [`--experimental-test-coverage`][]
374+
command-line flag, code coverage is collected and statistics are reported once
375+
all tests have completed. If the [`NODE_V8_COVERAGE`][] environment variable is
376+
used to specify a code coverage directory, the generated V8 coverage files are
377+
written to that directory. Node.js core modules and files within
378+
`node_modules/` directories are not included in the coverage report. If
379+
coverage is enabled, the coverage report is sent to any [test reporters][] via
380+
the `'test:coverage'` event.
380381

381382
Coverage can be disabled on a series of lines using the following
382383
comment syntax:
@@ -411,7 +412,8 @@ which will be addressed in a future Node.js release:
411412

412413
* Although coverage data is collected for child processes, this information is
413414
not included in the coverage report. Because the command line test runner uses
414-
child processes to execute test files, it cannot be used with `--test-coverage`.
415+
child processes to execute test files, it cannot be used with
416+
`--experimental-test-coverage`.
415417
* Source maps are not supported.
416418
* Excluding specific files or directories from the coverage report is not
417419
supported.
@@ -1634,7 +1636,7 @@ added: v18.7.0
16341636
aborted.
16351637

16361638
[TAP]: https://testanything.org/
1637-
[`--test-coverage`]: cli.md#--test-coverage
1639+
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
16381640
[`--test-name-pattern`]: cli.md#--test-name-pattern
16391641
[`--test-only`]: cli.md#--test-only
16401642
[`--test-reporter-destination`]: cli.md#--test-reporter-destination

doc/node.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ Use the specified file as a security policy.
163163
.It Fl -experimental-shadow-realm
164164
Use this flag to enable ShadowRealm support.
165165
.
166+
.It Fl -experimental-test-coverage
167+
Enable code coverage in the test runner.
168+
.
166169
.It Fl -no-experimental-fetch
167170
Disable experimental support for the Fetch API.
168171
.
@@ -391,9 +394,6 @@ Specify the minimum allocation from the OpenSSL secure heap. The default is 2. T
391394
.It Fl -test
392395
Starts the Node.js command line test runner.
393396
.
394-
.It Fl -test-coverage
395-
Enable code coverage in the test runner.
396-
.
397397
.It Fl -test-name-pattern
398398
A regular expression that configures the test runner to only execute tests
399399
whose name matches the provided pattern.

lib/internal/process/pre_execution.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ function setupCodeCoverage() {
285285
// Resolve the coverage directory to an absolute path, and
286286
// overwrite process.env so that the original path gets passed
287287
// to child processes even when they switch cwd. Don't do anything if the
288-
// --test-coverage flag is present, as the test runner will handle coverage.
289-
if (process.env.NODE_V8_COVERAGE && !getOptionValue('--test-coverage')) {
288+
// --experimental-test-coverage flag is present, as the test runner will
289+
// handle coverage.
290+
if (process.env.NODE_V8_COVERAGE &&
291+
!getOptionValue('--experimental-test-coverage')) {
290292
process.env.NODE_V8_COVERAGE =
291293
setupCoverageHooks(process.env.NODE_V8_COVERAGE);
292294
}

lib/internal/test_runner/harness.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function createProcessEventHandler(eventName, rootTest) {
5555
}
5656

5757
function configureCoverage(rootTest) {
58-
if (!getOptionValue('--test-coverage')) {
58+
if (!getOptionValue('--experimental-test-coverage')) {
5959
return null;
6060
}
6161

lib/internal/test_runner/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const {
4848
triggerUncaughtException,
4949
} = internalBinding('errors');
5050

51-
const kFilterArgs = ['--test', '--test-coverage', '--watch'];
51+
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
5252
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
5353

5454
// TODO(cjihrig): Replace this with recursive readdir once it lands.

src/node_options.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
151151
if (test_runner_coverage) {
152152
// TODO(cjihrig): This restriction can be removed once multi-process
153153
// code coverage is supported.
154-
errors->push_back("--test-coverage cannot be used with --test");
154+
errors->push_back(
155+
"--experimental-test-coverage cannot be used with --test");
155156
}
156157

157158
if (syntax_check_only) {
@@ -561,7 +562,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
561562
AddOption("--test",
562563
"launch test runner on startup",
563564
&EnvironmentOptions::test_runner);
564-
AddOption("--test-coverage",
565+
AddOption("--experimental-test-coverage",
565566
"enable code coverage in the test runner",
566567
&EnvironmentOptions::test_runner_coverage);
567568
AddOption("--test-name-pattern",

test/parallel/test-runner-coverage.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ function getCoverageFixtureReport() {
3737
return report;
3838
}
3939

40-
test('--test-coverage and --test cannot be combined', () => {
40+
test('--experimental-test-coverage and --test cannot be combined', () => {
4141
// TODO(cjihrig): This test can be removed once multi-process code coverage
4242
// is supported.
43-
const result = spawnSync(process.execPath, ['--test', '--test-coverage']);
43+
const args = ['--test', '--experimental-test-coverage'];
44+
const result = spawnSync(process.execPath, args);
4445

4546
// 9 is the documented exit code for an invalid CLI argument.
4647
assert.strictEqual(result.status, 9);
4748
assert.match(
48-
result.stderr.toString(), /--test-coverage cannot be used with --test/
49+
result.stderr.toString(),
50+
/--experimental-test-coverage cannot be used with --test/
4951
);
5052
});
5153

@@ -55,7 +57,7 @@ test('handles the inspector not being available', (t) => {
5557
}
5658

5759
const fixture = fixtures.path('test-runner', 'coverage.js');
58-
const args = ['--test-coverage', fixture];
60+
const args = ['--experimental-test-coverage', fixture];
5961
const result = spawnSync(process.execPath, args);
6062

6163
assert(!result.stdout.toString().includes('# start of coverage report'));
@@ -70,7 +72,7 @@ test('coverage is reported and dumped to NODE_V8_COVERAGE if present', (t) => {
7072
}
7173

7274
const fixture = fixtures.path('test-runner', 'coverage.js');
73-
const args = ['--test-coverage', fixture];
75+
const args = ['--experimental-test-coverage', fixture];
7476
const options = { env: { ...process.env, NODE_V8_COVERAGE: tmpdir.path } };
7577
const result = spawnSync(process.execPath, args, options);
7678
const report = getCoverageFixtureReport();
@@ -87,7 +89,7 @@ test('coverage is reported without NODE_V8_COVERAGE present', (t) => {
8789
}
8890

8991
const fixture = fixtures.path('test-runner', 'coverage.js');
90-
const args = ['--test-coverage', fixture];
92+
const args = ['--experimental-test-coverage', fixture];
9193
const result = spawnSync(process.execPath, args);
9294
const report = getCoverageFixtureReport();
9395

0 commit comments

Comments
 (0)