gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Error when using => $ istanbul report --include #596

Open ORESoftware opened 8 years ago

ORESoftware commented 8 years ago

Here is my directory structure:

screenshot 2016-04-11 14 31 22

When I run:

istanbul report --include coverage/test6 coverage/test8

I get:

/usr/local/lib/node_modules/istanbul/lib/reporter.js:58
            throw inputError.create('Invalid report format [' + fmt + ']');
            ^

Error: Invalid report format [coverage/test8]
    at Object.module.exports.create (/usr/local/lib/node_modules/istanbul/lib/util/input-error.js:7:15)
    at Object.Reporter.add (/usr/local/lib/node_modules/istanbul/lib/reporter.js:58:30)
    at /usr/local/lib/node_modules/istanbul/lib/reporter.js:69:18
    at Array.forEach (native)
    at Object.Reporter.addAll (/usr/local/lib/node_modules/istanbul/lib/reporter.js:68:14)
    at ReportCommand.Command.mix.run (/usr/local/lib/node_modules/istanbul/lib/command/report.js:101:18)
    at runCommand (/usr/local/lib/node_modules/istanbul/lib/cli.js:83:19)
    at runToCompletion (/usr/local/lib/node_modules/istanbul/lib/cli.js:87:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/istanbul/lib/cli.js:93:5)
    at Module._compile (module.js:409:26)

Any idea why?

ORESoftware commented 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!

codekirei commented 8 years ago

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!

ORESoftware commented 8 years ago

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?

ORESoftware commented 8 years ago

here is new directory structure with coverage-final.json there.

screenshot 2016-04-11 16 12 19

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?

ORESoftware commented 8 years ago

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

codekirei commented 8 years ago

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?).

ORESoftware commented 8 years ago

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

codekirei commented 8 years ago

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.

ORESoftware commented 8 years ago

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.

codekirei commented 8 years ago

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'

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:

ORESoftware commented 8 years ago

it's perfect working with the info right now!

ORESoftware commented 8 years ago

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

ORESoftware commented 8 years ago

works! that's pretty sweet, I must thank you for your kind help. You could easily turn that into a blogpost! Try Medium.com :)

codekirei commented 8 years ago

Hey great! You're welcome :smile:

And thanks for the blogpost recommendation — I just might do that.