From bf9854ff45fc2284ae9a40570679b6087f57d217 Mon Sep 17 00:00:00 2001 From: marco-ippolito Date: Thu, 4 Jan 2024 13:16:45 +0100 Subject: [PATCH] test_runner: create flag --check-coverage to enforce code coverage --- doc/api/cli.md | 17 +++++++++++++ doc/api/test.md | 15 +++++++++++ doc/node.1 | 7 ++++++ lib/internal/test_runner/test.js | 10 +++++++- lib/internal/test_runner/utils.js | 10 ++++++++ src/node_options.cc | 3 +++ src/node_options.h | 1 + .../test-runner/output/coverage_check.js | 25 +++++++++++++++++++ .../output/coverage_check.snapshot | 23 +++++++++++++++++ .../output/coverage_insufficient.js | 25 +++++++++++++++++++ .../output/coverage_insufficient.snapshot | 24 ++++++++++++++++++ 11 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/test-runner/output/coverage_check.js create mode 100644 test/fixtures/test-runner/output/coverage_check.snapshot create mode 100644 test/fixtures/test-runner/output/coverage_insufficient.js create mode 100644 test/fixtures/test-runner/output/coverage_insufficient.snapshot diff --git a/doc/api/cli.md b/doc/api/cli.md index 072b3b8ead55b8..e83fe2a82b2249 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -887,11 +887,28 @@ changes: description: This option can be used with `--test`. --> +> Stability: 1 - Experimental + When used in conjunction with the `node:test` module, a code coverage report is 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=coverage_threshold` + + + +> Stability: 1 - Experimental + +The `--check-coverage` CLI flag, used in conjunction with the `--experimental-test-coverage` commands, +enforce a specific test coverage threshold. +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 result in a failure. + ### `--experimental-vm-modules`