Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top