Skip to content

Commit 1ecc03e

Browse files
committed
doc,lib,src,test: rename --test-coverage
Add experimental to the name as requested during review. PR-URL: nodejs#46017 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent 8c95cb0 commit 1ecc03e

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
@@ -436,6 +436,17 @@ added:
436436

437437
Use this flag to enable [ShadowRealm][] support.
438438

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

441452
<!-- YAML
@@ -1233,17 +1244,6 @@ Starts the Node.js command line test runner. This flag cannot be combined with
12331244
See the documentation on [running tests from the command line][]
12341245
for more details.
12351246

1236-
### `--test-coverage`
1237-
1238-
<!-- YAML
1239-
added: REPLACEME
1240-
-->
1241-
1242-
When used in conjunction with the `node:test` module, a code coverage report is
1243-
generated as part of the test runner output. If no tests are run, a coverage
1244-
report is not generated. See the documentation on
1245-
[collecting code coverage from tests][] for more details.
1246-
12471247
### `--test-name-pattern`
12481248

12491249
<!-- YAML

doc/api/test.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,14 @@ internally.
372372

373373
## Collecting code coverage
374374

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

383384
Coverage can be disabled on a series of lines using the following
384385
comment syntax:
@@ -413,7 +414,8 @@ which will be addressed in a future Node.js release:
413414

414415
* Although coverage data is collected for child processes, this information is
415416
not included in the coverage report. Because the command line test runner uses
416-
child processes to execute test files, it cannot be used with `--test-coverage`.
417+
child processes to execute test files, it cannot be used with
418+
`--experimental-test-coverage`.
417419
* Source maps are not supported.
418420
* Excluding specific files or directories from the coverage report is not
419421
supported.
@@ -1714,8 +1716,8 @@ added:
17141716
aborted.
17151717

17161718
[TAP]: https://testanything.org/
1719+
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
17171720
[`--import`]: cli.md#--importmodule
1718-
[`--test-coverage`]: cli.md#--test-coverage
17191721
[`--test-name-pattern`]: cli.md#--test-name-pattern
17201722
[`--test-only`]: cli.md#--test-only
17211723
[`--test-reporter-destination`]: cli.md#--test-reporter-destination

doc/node.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ Use the specified file as a security policy.
160160
.It Fl -experimental-shadow-realm
161161
Use this flag to enable ShadowRealm support.
162162
.
163+
.It Fl -experimental-test-coverage
164+
Enable code coverage in the test runner.
165+
.
163166
.It Fl -no-experimental-fetch
164167
Disable experimental support for the Fetch API.
165168
.
@@ -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
@@ -301,8 +301,10 @@ function setupCodeCoverage() {
301301
// Resolve the coverage directory to an absolute path, and
302302
// overwrite process.env so that the original path gets passed
303303
// to child processes even when they switch cwd. Don't do anything if the
304-
// --test-coverage flag is present, as the test runner will handle coverage.
305-
if (process.env.NODE_V8_COVERAGE && !getOptionValue('--test-coverage')) {
304+
// --experimental-test-coverage flag is present, as the test runner will
305+
// handle coverage.
306+
if (process.env.NODE_V8_COVERAGE &&
307+
!getOptionValue('--experimental-test-coverage')) {
306308
process.env.NODE_V8_COVERAGE =
307309
setupCoverageHooks(process.env.NODE_V8_COVERAGE);
308310
}

lib/internal/test_runner/harness.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function createProcessEventHandler(eventName, rootTest) {
5757
}
5858

5959
function configureCoverage(rootTest) {
60-
if (!getOptionValue('--test-coverage')) {
60+
if (!getOptionValue('--experimental-test-coverage')) {
6161
return null;
6262
}
6363

lib/internal/test_runner/runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const {
4949
exitCodes: { kGenericUserError },
5050
} = internalBinding('errors');
5151

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

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

src/node_options.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
143143
if (test_runner_coverage) {
144144
// TODO(cjihrig): This restriction can be removed once multi-process
145145
// code coverage is supported.
146-
errors->push_back("--test-coverage cannot be used with --test");
146+
errors->push_back(
147+
"--experimental-test-coverage cannot be used with --test");
147148
}
148149

149150
if (syntax_check_only) {
@@ -555,7 +556,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
555556
AddOption("--test",
556557
"launch test runner on startup",
557558
&EnvironmentOptions::test_runner);
558-
AddOption("--test-coverage",
559+
AddOption("--experimental-test-coverage",
559560
"enable code coverage in the test runner",
560561
&EnvironmentOptions::test_runner_coverage);
561562
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)