From f1fb090cfaa6156347b075673280e458ce92b961 Mon Sep 17 00:00:00 2001 From: marco-ippolito Date: Thu, 4 Jan 2024 13:16:45 +0100 Subject: [PATCH 1/3] test_runner: create flag --check-coverage to enforce code coverage --- doc/api/cli.md | 63 +++++++++++++++++++ doc/api/test.md | 15 +++++ doc/node.1 | 18 ++++++ lib/internal/test_runner/test.js | 21 ++++++- lib/internal/test_runner/tests_stream.js | 3 +- lib/internal/test_runner/utils.js | 41 ++++++++++++ src/node_options.cc | 12 ++++ src/node_options.h | 4 ++ .../test-runner/output/coverage_check.js | 25 ++++++++ .../output/coverage_check.snapshot | 23 +++++++ .../output/coverage_insufficient.js | 25 ++++++++ .../output/coverage_insufficient.snapshot | 26 ++++++++ .../output/coverage_thresholds_no_check.js | 26 ++++++++ .../coverage_thresholds_no_check.snapshot | 23 +++++++ test/parallel/test-runner-output.mjs | 3 + .../test-runner-test-coverage-check.js | 52 +++++++++++++++ 16 files changed, 377 insertions(+), 3 deletions(-) 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 create mode 100644 test/fixtures/test-runner/output/coverage_thresholds_no_check.js create mode 100644 test/fixtures/test-runner/output/coverage_thresholds_no_check.snapshot create mode 100644 test/parallel/test-runner-test-coverage-check.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 072b3b8ead55b8..bcfbdff0c7837e 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -892,6 +892,69 @@ 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 test coverage thresholds for the specified checks +(`--lines`, `--branches`, `--functions`) are respected. + +### `--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. + +### `--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. + +### `--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. + ### `--experimental-vm-modules`