Node JS test coverage issue with Istanbul

烈酒焚心 提交于 2019-12-10 19:44:02

问题


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?


回答1:


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.




回答2:


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



回答3:


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

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



来源:https://stackoverflow.com/questions/21345025/node-js-test-coverage-issue-with-istanbul

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!