I am trying to get Istanbul to work.
I keep getting this message at the end of running istanbul:
No coverage information was collected, exit without writing coverage information
I have tried everything I could find online as you can see:
"scripts": {
"start": "node ./bin/start.js",
"test": "mocha test --no-timeouts",
"debug_mocha": "node-debug --no-timeouts _mocha",
"eslint": "eslint .",
"jshint": "jshint --exclude ./node_modules .",
"istanbul": "istanbul cover --include-all-sources --hook-run-in-context node_modules/.bin/_mocha -- -u exports -R spec test/**/*",
"istanbul2":"istanbul cover node_modules/.bin/_mocha -- -u exports -R spec test/**/*",
"istanbul1":"istanbul cover node_modules/.bin/_mocha -- test/**/*",
"istanbul0":"istanbul cover _mocha test/**/*.js",
"istanbul3":"istanbul cover _mocha -- -R spec --recursive test"
}
my .istanbul.yml file is at the root of the project and looks like istanbul is picking it up successfully.
//.istanbul.yml
instrumentation:
compact: false
save-baseline: true
reporting:
reports:
- lcov
- cobertura
What am I missing?
One of the most popular reporters is an HTML reporter. HTML reporters are simple to view and can be easily hosted. Now when you run your Mocha command, you're going to see a new coverage folder appear in the root of your project. Inside that folder is an HTML file that shows the latest test run.
To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
Mocha allows asynchronous testing, test coverage reports, and use of any assertion library. Chai is a BDD / TDD assertion library for NodeJS and the browser that can be delightfully paired with any javascript testing framework. Basically, mocha is a framework and chai is a library.
How Istanbul works. Istanbul instruments your ES5 and ES2015+ JavaScript code with line counters, so that you can track how well your unit-tests exercise your codebase. The nyc command-line-client for Istanbul works well with most JavaScript testing frameworks: tap, mocha, AVA, etc.
Got it, finally.
https://github.com/gotwarlost/istanbul/issues/44#issuecomment-57708358 says:
Using _mocha directly does not work on windows. Please use the full path to the JS file instead
Then, after a little experimentation, victory:
istanbul cover C:/dev/my_project/node_modules/mocha/bin/_mocha --
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With