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?

有帮助吗?

解决方案

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 ./

In my case the following command worked when run as a script defined in package.json:

istanbul cover ../jasmine/bin/jasmine.js

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top