diff --git a/doc/api/cli.md b/doc/api/cli.md index 072b3b8ead55b8..c06b5966ba1d1c 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -892,6 +892,94 @@ generated as part of the test runner output. If no tests are run, a coverage report is not generated. See the documentation on [collecting code coverage from tests][] for more details. +### `--check-coverage` + + + +> Stability: 1 - Experimental + +The `--check-coverage` CLI flag, used in conjunction with +the `--experimental-test-coverage` command, enforces that +the test coverage thresholds specified by check +flags are respected: + +* [`--lines=threshold`][]: Sets the threshold for line coverage. +* [`--branches=threshold`][]: Sets the threshold for branch coverage. +* [`--functions=threshold`][]: Sets the threshold for function coverage. + +To enforce global 100% coverage set the value of the each flag to 100: + +```bash +node --test --experimental-test-coverage --check-coverage --lines=100 --branches=100 --functions=100 +``` + +If one of the specified coverage check falls below the threshold, +the test will exit with non zero code. + +### `--lines=threshold` + + + +> Stability: 1 - Experimental + +The `--lines` CLI flag, used in conjunction with the `--check-coverage` flag, +enforces a coverage threshold check for lines of code covered by the test. +It is expressed as a numerical value between `0` and `100`, +representing the percentage (e.g., 80 for 80% coverage). +If the coverage falls below the threshold, +the test will exit with non zero code. + +```bash +node --test --experimental-test-coverage --check-coverage --lines=80 +``` + +### `--branches=threshold` + + + +> Stability: 1 - Experimental + +The `--branches` CLI flag, used in conjunction with the `--check-coverage` flag, +enforces a coverage threshold check for branches of code covered by the test. +It is expressed as a numerical value between `0` and `100`, +representing the percentage (e.g., 80 for 80% coverage). +If the coverage falls below the threshold, +the test will exit with non zero code. + +```bash +node --test --experimental-test-coverage --check-coverage --branches=80 +``` + +### `--functions=threshold` + + + +> Stability: 1 - Experimental + +The `--functions` CLI flag, used in conjunction with +the `--check-coverage`flag, enforces a coverage threshold check +for functions covered by the test. +It is expressed as a numerical value between `0` and `100`, +representing the percentage (e.g., 80 for 80% coverage). +If the coverage falls below the threshold, +the test will exit with non zero code. + +```bash +node --test --experimental-test-coverage --check-coverage --functions=80 +``` + ### `--experimental-vm-modules`