I am working on backend Typescript project where I am trying to get coverage report for unit test case. Jest returns empty coverage report in terminal as well as in html report stating nothing. I also tried with -- --coverage --watchAll=false
but it also returns the empty document.
package.json
"scripts":{
"unit-test": "jest --config='./config/jest/jest_unit.config.js' --forceExit --detectOpenHandles",
}
jest_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
}
},
};
Folder Structure
|-- 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 and terminal shows no coverage lines