Running Istanbul code coverage with mocha
Istanbul is a code coverage tool for JavaScript.
To run Istanbul with Mocha (a popular test framework), you can run this command:
npm install -g istanbul
istanbul cover node_modules/.bin/_mocha -- -- -u exports -R spec test/**/*
The reason we call _mocha</code> instead of mocha</code> is best explained in this github issue comment.
There are more options available when configuring Istanbul, see the command options here
Written by Paul Jensen
Related protips
4 Responses
istanbul cover --report html nodemodules/.bin/mocha -- -R spec
It's easier to find all your tests if you end with *Spec.js
This makes clear how to specify test directories other than "spec". Thank you!!
if you have a grunt task setup to run mocha (or whatever) , its even easier
istanbul cover --report html grunt test
Have you tried this with a require.js project? I have a project that runs mocha via grunt, using an html page to configure everything for mocha, either in the browser or with phantomjs. Have you been able to do coverage with istanbul with anything like this?
Thanks!