Jest,Typescript,ts-jest:覆盖范围略有不正确

Ric*_*ick 11 node.js typescript jestjs

我正在使用TypeScript,Jest和ts-jestNPM模块来编写项目.

当我运行我的测试时,我确实获得了一些覆盖率,但HTML报告并不完全正确:

代码覆盖问题

此外,一些功能被标记为未经测试,即使它们当然被调用.

我的package.json设置如下:

{
    "jest": {
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
    "collectCoverage": true,
    "collectCoverageFrom": [
      "src/**/*.{ts,tsx}"
    ],
    "coverageReporters": [
      "html",
      "json"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我的配置有问题吗?

Umi*_*mov 5

UPDATE

从jest @ 20开始,您可以传递mapCoverage选项并使用coverage/lcov-report/index.html文件.

我也一直在努力解决这个问题,但后来我注意到了这一点.

长篇短篇报道报道coverage/remapped/html/index.html归档.

  • 注意 [mapCoverage 现已从笑话中删除](https://github.com/kulshekhar/ts-jest/issues/340) (2认同)