I could not find my requirement for coverage in the jest docs. I have tried the following options but could not find the required solution to get jest coverage only for changed code.
npm test -- --coverage --onlyChanged
This runs only changed tests but shows coverage for full suite.
npm test -- --coverage --changedSince=base-branch
This runs all tests and shows coverage for full suite.
Found this discussion and it seems this issue is fixed. I am not sure why this is not working though?
Jest supports this out of the box.
jest --coverage --changedSince=master --coverageThreshold='{"global":{"statements":"50","branches":"50","functions":"50","lines":"50"}}'
The above command will only calculate the coverage for the code which was changed as compared to your master branch.
For this changed code you can also set the threshold coverage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With