Istanbul coverage with mocha test cases only showing coverage report for spec files (test files)

Istanbul coverage with mocha test cases only showing coverage report for spec files (test files)



Istanbul coverage report only shows coverage report for the spec files i.e the test files and not the original router and controllers files.



It displays 100% coverage for spec files and 0% for the router files.



The command i am using is npm test:


"test": "NODE_ENV=development istanbul cover --include-all-sources --root ./server ./node_modules/.bin/_mocha -- --compilers js:babel-core/register --recursive './server/**/**/**/*-spec.js'"



Below is the screenshot of the coverage report html file by istanbul
enter image description here




1 Answer
1



I manage to make it work for me, maybe you can pick some of my configs and apply them to your environment



My current packages version


"@babel/core": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-plugin-istanbul": "^5.0.1",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"nyc": "^13.0.1"



Update/Create your .babelrc adding the pluging for istanbul


.babelrc




"plugins": ["istanbul"]



Create a config file for istanbul: .nycrc and paste this configuration


.nycrc



"require": ["@babel/register"],
"exclude": ["**/*.test,spec.js"],
"all": true,
"instrument": false



You can check for more options in the official nyc repository



./node_modules/.bin/nyc mocha **/*.test,spec.js


./node_modules/.bin/nyc mocha **/*.test,spec.js



or



npx nyc mocha **/*.test,spec.js


npx nyc mocha **/*.test,spec.js



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)