4

I have a monorepo project, created with lerna. And, I use Karma+Jasmine for the unit testing. The project structure looks as follows:

|-packages
| |-package1
| | |-coverage
| | | |-cobertura
| | | | |-coverage.xml  // here goes the coverage report in cobertura format
| | | |-Browser1
| | | | |-html          // here goes the reports in html (istanbul) for Browser 1
| | | |-Browser2
| | |   |-html          // here goes the reports in html (istanbul) for Browser 2
| | |-src
| | |-tests
| |-package2
| | |-coverage
| | | |-cobertura
| | | | |-coverage.xml
| | | |-Browser1
| | | | |-html        
| | | |-Browser2
| | |   |-html        
| | |-src
| | |-tests
| .
| .
| .
|-karma.conf.js

The test setup is working properly and generating the html reports as well as the coverage.xml in Cobertura format inside the each individual package. In TFS CI, I have a "Publish Code Coverage Results" build step to publish the coverage results with following values for different options:

  • Code Coverage Tool: Cobertura
  • Summary File: $(System.DefaultWorkingDirectory)\packages\*\coverage\cobertura\coverage.xml
  • Report Directory: $(System.DefaultWorkingDirectory)\packages\*\coverage (for HTML reports)

However, the build step warns about following

Multiple file or directory matches were found. Using the first match: C:\MyAgent\path\to\packages\package1\coverage\cobertura\coverage.xml

Multiple file or directory matches were found. Using the first match: C:\MyAgent\path\to\packages\package1\coverage

Naturally it also shows the coverage results for only one package. Is there any way to publish all coverage reports without adding a build step in CI for each package?

Community
  • 1
  • 1
Sayan Pal
  • 4,768
  • 5
  • 43
  • 82

1 Answers1

3

Seems you are using the Publish Code Coverage Results task, it's unlike to use Publish test results task. You could not be able to publish multiple coverage test results in a single task.

The Arguments of this task is Summary File not like Test results files of Publish Test Results

There are two coverage.xml file in your file structure. So it will only use the first match just as message mentioned. Source code of the task for your reference.

You have to add another Publish Code Coverage Results task in build pipeline for each package.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • 1
    You confirmed my fear. However, in my monorepo there are quite a few projects. Adding a task for each of those package will certainly increase the overhead for the existing as well as the new packages in future. However, if there is no other way, then I guess I will eventually go with this. – Sayan Pal Mar 21 '18 at 17:32
  • @PatrickLu-MSFT, Even I want to display Code coverage results using two coverage.xml files and I even used Two Publish Code Coverage Results tasks but the TFS 2017 Build definition displays code coverage of the last task only. Is there any other way to display Code coverage using two coverage files? – SRP Dec 11 '18 at 13:05
  • @SRP You can use **/coverage.cobertura.xml as summaryFileLocation parameter. Then PublishCodeCoverageResults@1 task will create summary html report from all test projects. Hover still one result is published to devops statistics, but report contains results from all files. – djsowa Nov 29 '19 at 21:48
  • @djsowa, we can use Report Generator task present in TFS Marketplace https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator to display the code coverage result of multiple cobertura.xml. This task converts all the cobertura.xml files into a single cobertura.xml and then we can use this file in Publish Code Coverage Results to display our codecoverage. – SRP Dec 03 '19 at 06:31