3

I have a JavaScript file that generates a code-coverage report via karma-coverage. Karma-coverage generates reports via Istanbul from my understanding. At this time, istanbul generates two files of interest: an html report, and a .json file.

The HTML report has percentages around statement coverage, branch coverage, function coverage, and line coverage. A sample of the HTML report can be seen here: http://gotwarlost.github.io/istanbul/public/coverage/lcov-report/index.html

The .json file gets generated in a file called coverage.json. A sample of the coverage.json file can bee seen here: http://gotwarlost.github.io/istanbul/public/coverage/coverage.json.

For the life of me, I can't figure how the HTML report gets the statement, coverage, branch and function coverage percentages from the .json file. However, I to get the statement, coverage, branch, and function coverage percentages from the .json file.

Am I misunderstanding what the .json file is? Isn't there just a summarization in the .json file?

1 Answer 1

2

For the life of me, I can't figure how the HTML report gets the statement, coverage, branch and function coverage percentages from the .json file

That's because it doesn't :)

Those two files gets generated but has otherwise nothing to do with each other. They are just two versions of the result, two reports. They are two representations of the same information.

Why would I need the json-file, you might ask. That would be if you needed to use that information as input for another program.

An example of that is something I work with now. I'm using the output from my coverage reporter to generate colored lines in my editor to tell me what is covered. As you an imagine, it is easier for me to parse a json-file (or an lcov-file in my case, same thing different syntax), than the HTML-version.

And to clarify: Karma only runs your plugins. Istanbul does the coverage testing, and generates output that your reporters knows how to deal with. And those reporters generates (in your case) an HTML-file and a JSON-file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.