Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get jest coverage only for changed files?

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?

like image 813
Shanika Ediriweera Avatar asked Nov 27 '19 06:11

Shanika Ediriweera


Video Answer


1 Answers

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.

like image 170
Pulkit Gupta Avatar answered Oct 17 '22 04:10

Pulkit Gupta