Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring code coverage report for Karma on TeamCity

We are setting up TeamCity to run our jasmine tests using node and karma.

The tests run fine and results are reported under the "Tests" tab in TeamCity.

However we would like to report code coverage in TeamCity (and even set Build Failure Conditions on the level).

I have installed the karma-coverage module

npm install karma-coverage --save-dev

And tried to configure it in karma.conf.js by adding

preprocessors: {
 'myProject/Scripts/app/**/*.js': 'coverage'
},

reporters: ['progress', 'coverage'],

When karma is run, no errors are reported, and lots of files are created below the folder coverage, including a very nicely formatted code coverage report in index.html

But nothing new shows up in TeamCity. No "Code Coverage" tab.

How do I configure karma to produce reports that show up in TeamCity?

Perhaps I can use set coverageReporter to something appropriate, but what? This setting makes no difference:

coverageReporter: {
    type : 'html',
    dir : 'coverage/'
},

Bonus question: how do I set Build Failure Conditions on the karma reported code coverage?

like image 555
Klas Mellbourn Avatar asked Oct 09 '13 08:10

Klas Mellbourn


People also ask

How do I generate a coverage report on karma?

To activate the coverage reporter add this to your configuration file. reporters = ['coverage']; This will create a coverage report for every browser that the tests are run in. In addition, it will create a JSON file that outputs the intermediate data.

How do I enable code coverage in TeamCity?

To get the code coverage information displayed in TeamCity for the supported tools, you need to configure it in the dedicated section of a build runner's settings page. The following build runners include code coverage support: The code coverage results can be viewed on the Overview tab of Build Results.

How do I configure code coverage?

Configure coveragePress Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Coverage. Define how the collected coverage data will be processed: Show options before applying coverage to the editor: show the Code Coverage dialog every time you run a new run configuration with code coverage.


3 Answers

The easiest way to get TeamCity to recognize your coverage report is to output a build artifact that contains that nice html coverage report.

Edit the configuration settings for your build and under Artifact Paths add something like:

coverage/** => coverage.zip

TeamCity will recognize the coverage.zip artifact if it finds the index.html file in the root and will add a Code Coverage tab to each build.

Source: https://confluence.jetbrains.com/pages/viewpage.action?pageId=74847395#HowTo...-ImportcoverageresultsinTeamCity (Teamcity version 9.x)

like image 86
chris.m.gladd Avatar answered Sep 17 '22 22:09

chris.m.gladd


In my case the report was successfully generated into coverage.zip, but the code coverage tab wasn't visible in build report.

I had to manually add the report tab in Project Settings and provide a full path to the index.html file

enter image description here

like image 39
ekimpl Avatar answered Sep 19 '22 22:09

ekimpl


Don't know, if the sequence is important, and shouldn't you use [] brackets at preprocessors entries?

Try the following:

reporters: ['progress', 'coverage'],

preprocessors: {
 'myProject/Scripts/app/**/*.js': ['coverage']
},
like image 41
PIT Avatar answered Sep 18 '22 22:09

PIT