Reputation: 54
I have used nyc for getting code coverage for my nodeJs apis written in typescript. I have written test methods for all apis and controllers. Nyc is configured and working fine for getting coverage for controllers but nyc is not covering API code block even after all api having unit tests.
scripts used for running test methods -
"test":"mocha --timeout 99999 -r ts-node/register ./test/**/*.spec.ts --recursive --exit" "coverage":"nyc --reporter text-summary --reporter html --include src npm test"
src contains all the controller and api files.
Upvotes: 2
Views: 2325
Reputation: 799
The combination of typescript +mocha + nyc can be tricky to get right as many small details can mess up the proper cover reports.
Specifically it seems your missing the file extensions needed and some other typescript related settings.
Here's a valid .nycrc.yml
extends: "@istanbuljs/nyc-config-typescript"
reporter:
- html
- lcovonly
- clover
# those 2 are for commandline outputs
- text
- text-summary
report-dir: coverage
I have a pretty detailed full example for typescript with recent versions, linting and quality settings included as well as some more complex mocking and stubbing tests. It also covers fully non called files what most settings don't do whilst preserving correct coverage. Maybe it can help you :)
https://github.com/Flowkap/typescript-node-template
Also note the usage of .mocharc.yml for the needed mocha configs. It really is tricky to align those to nyc. VsCode launch config also included.
Upvotes: 1