Code coverage report using Karma (and Istanbul)

338 views
Skip to first unread message

pdeol...@gmail.com

unread,
Jun 23, 2015, 7:12:11 AM6/23/15
to karma...@googlegroups.com
Hi,

I am working on adding unit tests for a client application developed using AngularJS. I am using Karma with Jasmine to add unit test and ultimate goal is to generate code coverage for the same using Istanbul code coverage tool which is the default coverage tool with Karma. Attached is the karma.conf.js file that I am using.

Currently, I am instrumenting only a single file (the archived-chat.js) using 'coverage' tag and have included a test case using Jasmine for this file.
The test runs successfully using Karma and it also generates code coverage report in coverage folder. I am able to get the line, function, branch coverage etc. in percentage.

However, when I click on the link to view the line by line coverage for the individual file, it opens up the html for the file which doesn't have any red/green marking to show what is covered and what is not covered. Please have a look at the attached html file. I am expecting it to show green/red marking and display line by line coverage.
Can someone throw some light as to what I am missing? Any help in this regard is greatly appreciated.

Some more information:

This is the folder structure of my application: I am running karma from the tests folder...

-ipocc-ui-chromeapp
      -app
            -scripts                 //app source files reside in here
                  -controllers      //app controller source files (this is angularJS terminology)
                  -services         //app services source files (this is angularJS terminology)
            -tests                   // jasmine tests and karma.conf.js reside here
      -node-modules            //local karma and plug-ins installation

Versions of karma and other plug-ins:

karma               0.12.36
karma-jasmine   0.3.5
karma-coverage 0.4.2
istanbul  0.3.15

karma.conf.js
archived-chat.js.html

pdeol...@gmail.com

unread,
Jun 26, 2015, 1:37:52 AM6/26/15
to karma...@googlegroups.com
I think I have got the problem. Looks like the folder structure that I am using is creating issues. The html report for individual file is not able to find the css files since there are in different folder, due to which it is not able to render itself properly.

Mike Parks

unread,
Jun 26, 2015, 1:59:32 AM6/26/15
to karma...@googlegroups.com
I had this issue as well. I believe it's a known bug in Istanbul. I don't recall the bandaid fix, but it had something to do with file paths using the wrong slash.

I may be remembering wrong, but I believe I just line 9 of node_modules > karma-coverage > node_modules > Istanbul > lib > report > HTML.js to be a path specific to my machine. It's a nasty hack, but it works until the big is resolved.

Reply all
Reply to author
Forward
0 new messages