Shanika Ediriweera
Shanika Ediriweera

Reputation: 2377

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?

Upvotes: 27

Views: 16369

Answers (1)

Pulkit Gupta
Pulkit Gupta

Reputation: 1059

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.

Upvotes: 21

Related Questions