Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get coverage maps using current ts-jest?

Similar to Jest, Typescript, ts-jest: Coverage is slightly incorrect - however the answer there applies to older versions of jest where the mapCoverage option existed.

mapCoverage has now been removed and my impression is that ts-jest should now provide coverage reports that work out of the box.

I have followed the ts-jest documentation to install and run ts-jest:

npm install --save-dev jest typescript ts-jest @types/jest
npx ts-jest config:init
npx jest --coverage --coverageDirectory='coverage'
open coverage/lcov-report/index.ts.html

However I can see that the coverage report generates incorrect maps:

enter image description here

How can I get coverage maps using current ts-jest?

I have tried adding collectCoverage: true to my jest.config.js which has not changed the output.

like image 612
mikemaccana Avatar asked Oct 25 '25 00:10

mikemaccana


1 Answers

Have you tried to specify:

    "compilerOptions": {
      ...
      "sourceMap": true,

in your tsconfig.json file?

This solved the problem for me.

Versions:

  • node 14.17.0
  • typescript: 4.5.4
  • ts-jest: 27.1.2
  • jest: 27.4.5
like image 110
Gabriel Avatar answered Oct 26 '25 15:10

Gabriel



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!