Reputation: 1651
I tried to set up Istanbul/Nyc/Mocha for test coverage for my project and although I was able to run Nyc successfully, I am only able to see some files being picked up for test coverage not all the .ts files that I have.
So when I run
npm run coverage
I get
-----------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------------|---------|----------|---------|---------|-------------------
All files | 0 | 100 | 100 | 0 |
develop-potta | 0 | 100 | 100 | 0 |
swagger.ts | 0 | 100 | 100 | 0 | 1
develop-potta/models | 0 | 100 | 100 | 0 |
students.ts | 0 | 100 | 100 | 0 | 1
swaggerDefinition.ts | 0 | 100 | 100 | 0 | 1
develop-potta/routes | 0 | 100 | 100 | 0 |
routescontroller.ts | 0 | 100 | 100 | 0 | 4-5
This only covers about 50% of my code base. For example I have a develop-potta/DBConnection/OracleConnection.ts which is also a ts file which isn't being picked up by my script. I am unable to figure out why? Could it be a certain naming convention? Could it be that I didn't export those modules?
Upvotes: 2
Views: 1338
Reputation: 799
Typescript + mocha + nyc can be picky. Especially the all: true setting messes up the coverage a lot. But as you mention it's hard to bring it cover all files. My template repo covers those cases. Maybe it can help you.
https://github.com/Flowkap/typescript-node-template
If you're only interested in coverage check the .ncyrc.yml and mocharc.yml as well as the call config in package.json. VsCode launch configs also included.
Upvotes: 2