Include code coverage report in VSTS, Is Test Adapter mandatory for VSTS?

3.9k views Asked by At

I am generating code coverage using Karma-coverage. I can host my output coverage folder on http-server and view it locally.

How do I make this report visible on VSTS code coverage tab?

Do I need to re-format my coverage result in VSTS compatible?

I have read about vsts-tasks, but I have no clue how to achieve the same.

Any help is appreciated.

2

There are 2 answers

2
Krishh On BEST ANSWER

VSTS Code coverage supports the outputted code coverage results in Jacoco or Cobertura formats. Karma-Coverage supports Cobertura format. Edit your karma.config.js for

karma-coverage:

coverageReporter: {
  type : 'cobertura',
  ...
}

karma-remap-istanbul:

remapIstanbulReporter: {
  reports: {
    cobertura: './coverage/cobertura.xml',
    ...
  }
}

karma-remap-coverage:

remapCoverageReporter: {
 cobertura: './coverage/cobertura.xml',
 ...
},

Once you configure the output format, you can use Publish Code Coverage task to upload code coverage data to VSTS.

2
gentiane On

With karma.conf.js file generated by angular CLI 1.2+, it is as simple as adding the cobertura report (instead of lcov report) in istanbul reporter :

coverageIstanbulReporter: {
  reports: ['html', 'cobertura'],
  fixWebpackSourcePaths: true
}

So when you will run your tests with the --code-coverage option, a file named coverage-cobertura.xml will be generated in the coverage directory.

Then in your TFS/VSTS build, you can add a Publish Code Coverage task and specify the cobertura XML file.