Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node JS test coverage issue with Istanbul

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?

like image 781
Joel Joel Binks Avatar asked Jan 17 '26 18:01

Joel Joel Binks


2 Answers

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.

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 ./
like image 38
Ryan W Kan Avatar answered Jan 19 '26 12:01

Ryan W Kan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!