user2630764
user2630764

Reputation: 622

Code coverage on multiple files

I have a application in node.js using mocha framework . I have two javascript source files ,for which I want to take the code coverage (viz a.js and b.js). I am using istanbul for this purpose .

Here the problem is I am not getting how to take code coverage for multiple files . I am using the following format :

istanbul cover node_modules/mocha/bin/_mocha a.js 


istanbul cover node_modules/mocha/bin/_mocha a.js b.js 

but unfortunately both the commands are giving the same code coverage, I think its taking only a.js code . Is there any solution for finding the code coverage for multiple files?

Upvotes: 4

Views: 2293

Answers (1)

Seth Holladay
Seth Holladay

Reputation: 9539

The problem here is how the arguments to Istanbul are being parsed.

Assuming that mocha a.js b.js works as you expect, then this should be the equivalent Istanbul command:

istanbul cover node_modules/mocha/bin/_mocha -- a.js b.js

Istanbul will split the arguments at -- and pass the ones on the right to the node script on the left. Once that is working correctly, Istanbul's coverage reports will work correctly.

An improvement on top of this would be to give mocha a directory instead of explicit filenames, if possible. That way, this code does not have to change if the filenames change.

You can also make coverage easier by using Intern.js for testing, which actually uses Istanbul and instruments all of your code automatically with very little setup.

Upvotes: 2

Related Questions