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
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.