Open ORESoftware opened 8 years ago
Ok so after combing some threads on Github, I believe the correct command to use is the following:
$ istanbul report --dir coverage --include **/*coverage.json json
Now, this seems to output a file called "coverage-final.json" in the coverage directory.
But my question now is, how do we view the consolidated report? Even though this new file exists, I am not sure if it is making a difference? How do I view the consolidated report? thanks!
How would you like to view the consolidated report? It appears that you are electing to output a json
report, and it looks like that's what you're getting with a coverage-final.json
file. It is then up to you to consume that json
output as you choose. Or are you saying there is an issue with the coverage-final.json
file?
If you want another type of report, you can use one of the other reporters — text
to print to console, teamcity
to consume with teamcity, html
for a web page you can serve locally and peruse in a browser, etc. Another option is to output lcov
and process it with something like lcov-summary.
I'm not sure I completely understand what you're looking for, but hopefully that helps!
Thanks! What I was looking for is an lcov-summary of the whole shebang. Given the coverage-final.json file, how can I generate an lcov-summary from it?
here is new directory structure with coverage-final.json there.
What confuses me is that I would have thought Istanbul would have generated a lcov-report for the whole thing (for coverage-final.json), and maybe it has?
Ok, perhaps what I am looking for is this:
$ istanbul report --dir coverage --include **/*coverage.json lcov
instead of
$ istanbul report --dir coverage --include **/*coverage.json json
with the json option, all it was doing was creating the coverage-final.json file. Perhaps with the lcov option (as opposed to lcov-only) it will output an .html file
That is precisely what I would try, yes!
Note that lcov
also generates an html report, while lcovonly
should just give you the lcov.info
file (perhaps lcov-final.info
, in this case?).
yeah, I guess I don't understand why you would just want the .json file and .info file? I guess if you had a separate html reporter or something
Exactly, it's to give you the option to process the raw output as you choose. There are all sorts of systems out there that process coverage reports, so rather than supporting all of them, it's easier to support the few most common while also providing raw json
and info
output for the edge cases.
For example, I like using coveralls for my open source projects, and coveralls consumes raw lcov.info
files. I still use the html
reporter while debugging locally, but it's very useful to have that condensed lcov output for external parsers like coveralls.
cool! Would you mind sharing the code that you have for coveralls that can consume the lcov.info file? I'd like to try it.
Sure! I usually use coveralls in tandem with travis-ci. Both are free for open source projects and authenticate through GitHub so you don't even need to set up another account:
For NodeJS projects, I include a .travis.yml
file in the project root that commonly looks something like this:
language: node_js
node_js:
- '5'
- '4'
- '0.12'
script: 'npm run cover -- --report lcovonly'
after_script: 'npm install coveralls && cat coverage/lcov.info | coveralls'
language
: what kind of test environment to set upnode_js
: which versions of node are installed with nvm and tested inscript
: the shell command that runs the tests
cover
is defined under scripts
in package.json
and usually looks something like "cover": "istanbul cover _mocha",
--
passes additional commands to the npm
script, in this case specifying which reporter to useafter_script
: runs after script
has finished — installs the coveralls package and cat
s the lcov.info
output from script
through a pipe to the coveralls
command it just installed (could also simply include coveralls as a dev dependency in package.json
to skip installing it here)Once you have a GitHub repo enabled on both travis and coveralls and you have a .travis.yml
file in said repo, every time you push code to GitHub, travis will automatically run your tests and send your coverage info to coveralls.
All that the say, the magic with coveralls is here:
cat coverage/lcov.info | coveralls
But if I'm recommending coveralls, I can't help but recommend travis as well. The two services together have been a really nice workflow for me.
As a side note, unless things have changed recently, travis is only able to do its remote testing in unix-like OSes, so projects that absolutely need CI in windows commonly use another service like appveyor for that. I'm pretty entrenched in Linux/OSX land these days so I haven't taken the time to set up windows CI on all my stuff yet (though I definitely should), but I thought it was worth mentioning.
That was probably (almost certainly) more than you were asking for — apologies for the verbosity :grin:
it's perfect working with the info right now!
CACSVML-16845:suman amills001c$ cat coverage/lcov.info | coveralls
/Users/amills001c/.nvm/versions/node/v4.3.2/lib/node_modules/coveralls/bin/coveralls.js:18 throw err; ^ Bad response: 422 {"message":"Couldn't find a repository matching this job.","error":true}
looks like I have to sign up on the coveralls site first via Github auth
works! that's pretty sweet, I must thank you for your kind help. You could easily turn that into a blogpost! Try Medium.com :)
Hey great! You're welcome :smile:
And thanks for the blogpost recommendation — I just might do that.
Here is my directory structure:
When I run:
istanbul report --include coverage/test6 coverage/test8
I get:
Any idea why?