x6jfwg
Last Updated: January 20, 2017
·
27.14K
· paulbjensen
3292448094f4c589c3be204c8a745025

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

4 Responses
Add your response

15461
30046572bfe022513ce39afed29e00ce

istanbul cover --report html nodemodules/.bin/mocha -- -R spec

It's easier to find all your tests if you end with *Spec.js

over 1 year ago ·
16269
130159528d3324772c412dbf2fafa2f4

This makes clear how to specify test directories other than "spec". Thank you!!

over 1 year ago ·
28053

if you have a grunt task setup to run mocha (or whatever) , its even easier

istanbul cover --report html grunt test

5 months ago ·
28524

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!

3 days ago ·