Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jest without code coverage constraint?

I am trying to inspect a single test so I run:

npm test alerts.actionCreators.test.js

The test passes, and then I get a huge printout of code coverage and then a failure for not meeting global standards. Can I skip this part of testing while I focus on the just whether the test passes or fails?

like image 637
smuggledPancakes Avatar asked May 14 '26 15:05

smuggledPancakes


2 Answers

I found a hack that mostly works: --collectCoverageOnlyFrom ''. With this the coverage table will be empty and take only about 5 lines.

like image 106
JJPandari Avatar answered May 17 '26 05:05

JJPandari


I would recommend adding a second test command to your package.json :

{
  "test:watch": "jest --watch-all",
  ...
}

Jest will watch for changes in your tests/implementation and re-run the tests automatically. It should not cover the tests in watch mode.

It's good idea to run a coverage on your code from time to time. To make sure jest excluded code you don't want to cover, make sure to configure your jest config accordingly:

{
  collectCoverageFrom: ["src/**/{!(*.d.ts),}.{ts,js,.tsx,.jsx}"],
  ...
}

More information about jest configuration can be found here.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!