Currently, I am conducting a test on my node.js written TypeScript code using mocha and chai. To measure the code coverage, I have incorporated nyc.
Moreover, in this project, I am utilizing Typeorm as an ORM tool and implementing inversify as an IoC container.
During the creation of unit test cases, the code coverage indicates that there are uncovered branches wherever there is a decorator such as @Inject or @Response being passed as a parameter in either a constructor or any method.
I suspect that the following configuration could be causing this issue:
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
However, disabling these configurations may lead to a failure in Typeorm functionality.
Here are some screenshots for reference:
https://i.sstatic.net/0VeHk.png
https://i.sstatic.net/LDZc3.png The content of the tsconfig.json file can be found below:
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"outDir": "dist",
"noImplicitAny": true,
"baseUrl": "./",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"types": [
"node",
"mocha"
],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts",
"migrations/**/*.ts"
],
"exclude": [
"./node_modules",
"./dist"
]
}
For running tests and generating test coverage reports, use the following npm commands:
"test": "mocha -r ts-node/register ./tests/unit/**/*.ts --exit",
"test:cov": "rimraf reports && rimraf .nyc_output && nyc mocha