I am running some node js unit tests using "Istanbul cover test.js", where test.js is the master test file which will call the actual scripts in our codebase. The problem is that the coverage report it generates is only on the test.js file and not on the actual lines of code in the codebase. Pardon me if this is a dumb question, but how do I get it to show coverage for the actual files that the tests refer to?
Asked
Active
Viewed 4,263 times
3 Answers
7
You have to run istanbul cover
against the tests that are run.
The example in the docs is a bit unclear about this: istanbul cover test.js
assumes that test.js
is the executable that is running all your tests, not the test itself.
For example, if you're using mocha
as your test runner, it should look like istanbul cover node_modules/.bin/_mocha
(assuming mocha is installed as local devDependency) or istanbul cover mocha
, if it's installed as global module.

Frederic
- 2,293
- 18
- 22
-
1Can you tell me how can I run jasmine with Istanbul then? I've tried "istanbul cover jasmine-node" (I am using it on Windows), it fails with Module._compile (module.js:439:25). Usually I launch jasmine-node with additional environment variables set, so I need to pass them somehow. – Aleksandr Oct 23 '14 at 09:26
-
@AlexShumilov `istanbul cover ./node_modules/jasmine-node/bin/jasmine-node spec/**/*.js` works for me. Be sure that none of your tests make the process "hang" after they're done or istanbul won't run. – ccnokes Jan 28 '15 at 21:58
1
on Windows:
If you installed jasmine-node globally:
istanbul cover /d/Users/rxxx/AppData/Roaming/npm/node_modules/jasmine-node/bin/jasmine-node ./
If you installed jasmine-node locally:
istanbul cover ../node_modules/jasmine-node/bin/jasmine-node ./

Ryan W Kan
- 380
- 3
- 16
0
In my case the following command worked when run as a script defined in package.json
:
istanbul cover ../jasmine/bin/jasmine.js

cjbarth
- 4,189
- 6
- 43
- 62