如何使用当前的 ts-jest 获取覆盖图?

mik*_*ana 4 typescript jestjs ts-jest

Jest、Typescript、ts-jest 类似:覆盖范围略有不正确- 但是那里的答案适用于mapCoverage存在该选项的旧版本的 jest。

mapCoverage现在已被删除,我的印象是 ts-jest 现在应该提供开箱即用的覆盖率报告。

我已按照ts-jest 文档安装并运行 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
Run Code Online (Sandbox Code Playgroud)

但是我可以看到覆盖率报告生成了不正确的地图:

在此输入图像描述

如何使用当前的 ts-jest 获取覆盖图?

我尝试添加collectCoverage: true到我的jest.config.js,但没有改变输出。

Gab*_*iel 5

您是否尝试过指定:

    "compilerOptions": {
      ...
      "sourceMap": true,
Run Code Online (Sandbox Code Playgroud)

在你的tsconfig.json文件中?

这为我解决了问题。

版本:

  • 节点 14.17.0
  • 打字稿:4.5.4
  • ts-笑话:27.1.2
  • 笑话:27.4.5