grunt-karma icon indicating copy to clipboard operation
grunt-karma copied to clipboard

Coverage does not seem to work when running grunt-karma with background

Open abierbaum opened this issue 11 years ago • 9 comments

I am trying to setup a grunt-based project to use karma with code coverage enabled. For some reason this doesn't seem to be working.

I have setup a sample project that shows the issue: https://github.com/abierbaum/test_karma/tree/dev/add_grunt

If I run:

./node_modules/grunt build

Then it will run in singleRun mode and the following output as expected.

~/Source/test_karma (dev/add_grunt *% u=)$ ./node_modules/.bin/grunt build
Running "clean:dist" (clean) task

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "karma:build" (karma) task
[2013-06-25 16:25:24.812] [DEBUG] config - autoWatch set to false, because of singleRun
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 28.0 (Linux)]: Connected on socket id wy4fHhIWpvTmRdOnOhDY
Chrome 28.0 (Linux) LOG: 'play file: '
Chrome 28.0 (Linux) LOG: { currentlyPlayingSong: {}, isPlaying: true }
Chrome 28.0 (Linux): Executed 5 of 5 SUCCESS (0.028 secs / 0.007 secs)

=============================== Coverage summary ===============================
Statements   : 93.33% ( 14/15 )
Branches     : 100% ( 2/2 )
Functions    : 85.71% ( 6/7 )
Lines        : 93.33% ( 14/15 )
================================================================================

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Done, without errors.

If instead I try to run using a watch and background: true, I get the following output where karma works, but it doesn't run the coverage.

~/Source/test_karma (dev/add_grunt *% u=)$ ./node_modules/.bin/grunt dev
Running "clean:dist" (clean) task
Cleaning "dist/"...OK

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Running "karma:unit" (karma) task

Running "watch" task
Waiting...OK
>> File "spec/PlayerSpec.js" changed.

Running "clean:dist" (clean) task
Cleaning "dist/"...OK

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Running "karma:unit:run" (karma) task
Chrome 28.0 (Linux) LOG: 'play file:  '
Chrome 28.0 (Linux) LOG: { currentlyPlayingSong: {}, isPlaying: true }
Chrome 28.0 (Linux): Executed 5 of 5 SUCCESS (0.026 secs / 0.01 secs)

Done, without errors.
Completed in 0.774s at Tue Jun 25 2013 16:27:50 GMT-0500 (CDT) - Waiting...

Any idea how to fix this up?

I am running Ubuntu 12.10 with node v0.10.12. The package versions I am using are shown in the package file: https://github.com/abierbaum/test_karma/blob/dev/add_grunt/package.json

abierbaum avatar Jun 25 '13 21:06 abierbaum

Having the same issue. Would be nice to see coverage in background mode.

thomasboyt avatar Jul 10 '13 22:07 thomasboyt

@abierbaum thanks for putting a sample together, I'll take a look.

geddski avatar Jul 15 '13 02:07 geddski

@abierbaum ok I see what you're seeing. Could you do me a favor in that sample project: create a branch that uses grunt-karma v 0.5.x (uses latest karma)? Would like to rule that out before digging further.

geddski avatar Jul 15 '13 02:07 geddski

@geddski I was having the same problem and the update seemed to do the trick.

Thank you.

cgardner avatar Oct 16 '13 16:10 cgardner

I had a look at the at the sample of @abierbaum that used karma v 0.5.x https://github.com/abierbaum/test_karma/tree/dev/karma_canary and the coverage report is generated by a 'singleRun' task. Has anyone managed to generate the coverage reports when grunt-karma is running in 'background: true' mode?

yianisn avatar Nov 21 '13 15:11 yianisn

In my experience using an outdated version is what causes this. Currently I'm using version 0.10.9 of Karma, version 0.1.5 of Karma Coverage and version 0.6.2 of the Grunt Karma plugin; using these versions I succeed in creating coverage reports when the background mode has been activated.

The NPM version that I'm running is 1.3.23.

RobbinHabermehl avatar Feb 04 '14 21:02 RobbinHabermehl

I still see this same issue with

,karma: {
    unit: {
        configFile: "test/karma.conf.js",
        background: true
    }
    ,ci: {
        configFile: "test/karma.conf.js",
        singleRun: true
    }
}

I get coverage output with the ci target, but not the unit one (run as grunt karma:unit watch).

nshew13 avatar Jun 05 '14 16:06 nshew13

@NShewmaker can you please check if this might be related to #33 where you were seeing that background=false was passed even though you specified true.

dignifiedquire avatar Sep 04 '14 12:09 dignifiedquire

:+1: I'd love to see updated coverage reports in console when tdd-ing

Xiphe avatar Oct 17 '14 06:10 Xiphe