Why is jest code coverage report showing inconsistent values?

Viewed 1706

I am trying to get 100% branch coverage. According to Jest's coverage report each individual file shows 100% coverage but "All files" report shows 96.97%.

If each file is 100%, shouldn't All files also be 100%?

The files that show 0 don't seem to be matter as a previous pull request shows the same files with 0% coverage but "All files" branch cov as 100%. It is only since adding in my new code / feature that I appear to have dropped coverage.

I am running the following to run my tests and get a coverage report:

jest --coverage --watchAll

Am I missing test coverage or is there an inconsistency with the way jest reports coverage?

code coverage report

1 Answers

Looks like src/env/index.ts had a turnery operator which wasn't being tested. This reduces branch coverage as it is a conditional that wasn't being tested.

In my case, I don't want to test my env file so I have added to my jest.config.js file

collectCoverageFrom: [
  '**/*.{ts,js}',
  '!env/index.ts', // <-- ignoring env file
  '!**/node_modules/**',
  '!**/build/**',
  '!**/dist/**',
  '!**/coverage/**'
],
Related