Skip to content

New CLI flag to exit with an error status if test coverage is incomplete #48739

Closed
@jaydenseric

Description

@jaydenseric

What is the problem this feature will solve?

When using the Node.js test runner in combination with the --experimental-test-coverage flag, it would be very useful to be able to also flag Node.js to exit the process with an error status (i.e. 1) if the coverage was not 100% complete, to be able to enforce complete code coverage in CI.

Until this feature exists, I won't be able to migrate projects from using coverage-node:

https://github.com/jaydenseric/coverage-node/tree/v8.0.0#command-coverage-node

Personally I only have interest in enforcing 100% code coverage or not enforcing it at all, but I can see how some teams might want to enforce a minimum percent of code coverage so they can iteratively work towards 100%, raising the minimum over time, and notice in CI if any contributions go against that goal.

What is the feature you are proposing to solve the problem?

We currently run tests like this:

node --enable-source-maps --experimental-test-coverage --test-reporter=spec --test

So I propose another flag --minimum-coverage (bikeshed the name) that can accept a percent number for the minimum coverage percent required to avoid the process exiting with an error status 1. E.g:

node --enable-source-maps --experimental-test-coverage --minimum-coverage=100 --test-reporter=spec --test

What alternatives have you considered?

  1. Changing the --experimental-test-coverage from a boolean to accepting a percent number for the minimum coverage percent required to avoid the process exiting with an error status 1.

    node --enable-source-maps --experimental-test-coverage=100 --test-reporter=spec --test
    

    I actually quite like this because it reduces the number of flags, but I'm not sure it's ok to change an existing flag already in use? Perhaps that's not a concern since it's experimental and also if the value is optional and defaults to the current behaviour it won't break projects already using --experimental-test-coverage.

  2. Enforce 100% code coverage by default, and use an environment variable to opt out of the enforcement. This is how coverage-node currently works:

    https://github.com/jaydenseric/coverage-node/tree/v8.0.0#command-coverage-node

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions