Skip to content

Commit 88f237c

Browse files
committed
test_runner: add --test-coverage flag
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
1 parent 8d3245e commit 88f237c

16 files changed

Lines changed: 65 additions & 52 deletions

doc/api/cli.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ added:
13861386
13871387
Enable the experimental [`node:stream/iter`][] module.
13881388

1389-
### `--experimental-test-coverage`
1389+
### `--test-coverage`
13901390

13911391
<!-- YAML
13921392
added:
@@ -1400,11 +1400,12 @@ changes:
14001400
description: This option can be used with `--test`.
14011401
-->
14021402

1403-
When used in conjunction with the `node:test` module, a code coverage report is
1404-
generated as part of the test runner output. If no tests are run, a coverage
1405-
report is not generated. See the documentation on
1403+
Enable code coverage collection in the test runner. If no tests are run, a
1404+
coverage report is not generated. See the documentation on
14061405
[collecting code coverage from tests][] for more details.
14071406

1407+
The legacy `--experimental-test-coverage` flag is supported as an alias.
1408+
14081409
### `--experimental-test-module-mocks`
14091410

14101411
<!-- YAML

doc/api/test.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ inherit Node.js options from the parent process, including those specified in
827827
test runner functionality:
828828

829829
* `--test` - Prevented to avoid recursive test execution
830-
* `--experimental-test-coverage` - Managed by the test runner
830+
* `--test-coverage` - Managed by the test runner
831831
* `--experimental-test-tag-filter` - Filter values are validated by the parent
832832
process and re-emitted to child processes
833833
* `--watch` - Watch mode is handled at the parent level
@@ -847,7 +847,7 @@ and configuration files are inherited by the child processes.
847847

848848
> Stability: 1 - Experimental
849849
850-
When Node.js is started with the [`--experimental-test-coverage`][]
850+
When Node.js is started with the [`--test-coverage`][]
851851
command-line flag, code coverage is collected and statistics are reported once
852852
all tests have completed. If the [`NODE_V8_COVERAGE`][] environment variable is
853853
used to specify a code coverage directory, the generated V8 coverage files are
@@ -894,7 +894,7 @@ There is also an lcov reporter that will generate an lcov file which can be
894894
used as an in depth coverage report.
895895

896896
```bash
897-
node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info
897+
node --test --test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info
898898
```
899899

900900
* No test results are reported by this reporter.
@@ -1408,7 +1408,7 @@ The following built-reporters are supported:
14081408

14091409
* `lcov`
14101410
The `lcov` reporter outputs test coverage when used with the
1411-
[`--experimental-test-coverage`][] flag.
1411+
[`--test-coverage`][] flag.
14121412

14131413
The exact output of these reporters is subject to change between versions of
14141414
Node.js, and should not be relied on programmatically. If programmatic access
@@ -4679,7 +4679,7 @@ test.describe('my suite', (suite) => {
46794679

46804680
[TAP]: https://testanything.org/
46814681
[Test tags]: #test-tags
4682-
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
4682+
[`--test-coverage`]: cli.md#--test-coverage
46834683
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
46844684
[`--experimental-test-tag-filter`]: cli.md#--experimental-test-tag-filterexpr
46854685
[`--import`]: cli.md#--importmodule

doc/node-config-schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@
510510
"type": "boolean",
511511
"description": "Type-stripping for TypeScript files."
512512
},
513+
"test-coverage": {
514+
"type": "boolean",
515+
"description": "enable code coverage in the test runner"
516+
},
513517
"test-coverage-branches": {
514518
"type": "number",
515519
"description": "the branch coverage minimum threshold"
@@ -887,6 +891,10 @@
887891
"additionalProperties": false,
888892
"required": [],
889893
"properties": {
894+
"test-coverage": {
895+
"type": "boolean",
896+
"description": "enable code coverage in the test runner"
897+
},
890898
"experimental-test-coverage": {
891899
"type": "boolean",
892900
"description": "enable code coverage in the test runner"

doc/node.1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,11 @@ Use this flag to enable ShadowRealm support.
769769
.It Fl -experimental-storage-inspection
770770
Enable experimental support for storage inspection
771771
.
772-
.It Fl -experimental-test-coverage
773-
When used in conjunction with the \fBnode:test\fR module, a code coverage report is
774-
generated as part of the test runner output. If no tests are run, a coverage
775-
report is not generated. See the documentation on
776-
collecting code coverage from tests for more details.
772+
.It Fl -test-coverage
773+
Enable code coverage collection in the test runner. If no tests are run, a
774+
coverage report is not generated. See the documentation on collecting code
775+
coverage from tests for more details.
776+
The legacy \fB--experimental-test-coverage\fR flag is supported as an alias.
777777
.
778778
.It Fl -experimental-test-module-mocks
779779
Enable module mocking in the test runner.

lib/internal/process/pre_execution.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,9 @@ function setupCodeCoverage() {
466466
// Resolve the coverage directory to an absolute path, and
467467
// overwrite process.env so that the original path gets passed
468468
// to child processes even when they switch cwd. Don't do anything if the
469-
// --experimental-test-coverage flag is present, as the test runner will
470-
// handle coverage.
469+
// --test-coverage flag is present, as the test runner will handle coverage.
471470
if (process.env.NODE_V8_COVERAGE &&
472-
!getOptionValue('--experimental-test-coverage')) {
471+
!getOptionValue('--test-coverage')) {
473472
process.env.NODE_V8_COVERAGE =
474473
setupCoverageHooks(process.env.NODE_V8_COVERAGE);
475474
}

lib/internal/test_runner/runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ let debug = require('internal/util/debuglog').debuglog('test_runner', (fn) => {
111111
const kIsolatedProcessName = Symbol('kIsolatedProcessName');
112112
const kFilterArgs = [
113113
'--test',
114+
'--test-coverage',
114115
'--experimental-test-coverage',
115116
'--test-randomize',
116117
'--watch',
@@ -201,7 +202,7 @@ function getRunArgs(path, { forceExit,
201202
const nodeOptionsSet = new SafeSet(processNodeOptions);
202203
const unknownProcessExecArgv = ArrayPrototypeFilter(
203204
process.execArgv,
204-
(arg) => !nodeOptionsSet.has(arg),
205+
(arg, i, arr) => !nodeOptionsSet.has(arg) && filterExecArgv(arg, i, arr),
205206
);
206207
ArrayPrototypePushApply(runArgs, unknownProcessExecArgv);
207208

lib/internal/test_runner/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function parseCommandLine() {
270270
}
271271

272272
const isTestRunner = getOptionValue('--test');
273-
const coverage = getOptionValue('--experimental-test-coverage');
273+
const coverage = getOptionValue('--test-coverage');
274274
const forceExit = getOptionValue('--test-force-exit');
275275
const sourceMaps = getOptionValue('--enable-source-maps');
276276
const updateSnapshots = getOptionValue('--test-update-snapshots');

src/node_options.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,12 +941,14 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
941941
kDisallowedInEnvvar,
942942
false,
943943
OptionNamespaces::kTestRunnerNamespace);
944-
AddOption("--experimental-test-coverage",
944+
AddOption("--test-coverage",
945945
"enable code coverage in the test runner",
946946
&EnvironmentOptions::test_runner_coverage,
947947
kDisallowedInEnvvar,
948948
false,
949949
OptionNamespaces::kTestRunnerNamespace);
950+
// TODO(cjihrig): Remove this alias in a semver major.
951+
AddAlias("--experimental-test-coverage", "--test-coverage");
950952
AddOption("--test-coverage-branches",
951953
"the branch coverage minimum threshold",
952954
&EnvironmentOptions::test_coverage_branches,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"test": {
33
"test-concurrency": 1,
4-
"experimental-test-coverage": true
4+
"test-coverage": true
55
}
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"test": {
3-
"experimental-test-coverage": true
3+
"test-coverage": true
44
}
55
}

0 commit comments

Comments
 (0)