我正在开发后端 Typescript 项目,我正在尝试获取单元测试用例的覆盖率报告。Jest 在终端和 html 报告中返回空的覆盖率报告,没有说明任何内容。我也尝试过,-- --coverage --watchAll=false但它也返回空文档。
包.json
"scripts":{
"unit-test": "jest --config='./config/jest/jest_unit.config.js' --forceExit --detectOpenHandles",
}
is_unit.config.js
/**
* @file Jest Unit Test Configuration File
*/
module.exports = {
roots: ['../../tests'],
testRegex: '.*_unit.test.(js|ts|tsx)?$',
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json',
},
},
moduleFileExtensions: ['ts', 'js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testEnvironment: 'node',
reporters: [
'default',
[
'../../node_modules/jest-html-reporter',
{
pageTitle: 'Unit Test Report',
outputPath: 'tests/reports/unit-test-report.html',
includeFailureMsg: true,
},
],
],
collectCoverage: true,
collectCoverageFrom: [
'../../api/**/*.ts'
],
moduleFileExtensions: ["ts", "js", "json"],
coverageDirectory: "../../coverage",
coveragePathIgnorePatterns: [
"<rootDir>/node_modules"
],
coverageReporters: [
"json",
"lcov",
"text"
],
coverageThreshold: {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
};
文件夹结构
|-- app
|-- controllers
|-- schemas
|-- config
|-- jest
|-- jest_unit.config.js
|-- package.json
|-- tests
|-- api
|-- modules
|-- m1
|-- controllers
|-- m1_controller_unit.test.ts
|-- m1_controller_integration.test.ts
|-- m2
|-- models
|-- m1_model_unit.test.ts
|-- m1_model_integration.test.ts
|-- m3
|-- schemas
|-- m1_schema_unit.test.ts
|-- m1_schema_integration.test.ts
Jest Coverage htm 和终端显示没有覆盖线
潇潇雨雨
白衣染霜花
明月笑刀无情
阿波罗的战车
相关分类