Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish code coverage not finding coverage file in Azure DevOps

I'm using Node 14.x and Jest 26.x. There is a npm test script in package.json file which contains the following:

cross-env NODE_ENV=test jest --coverage --forceExit

When I run it locally, it generates the code coverage report in ./coverage directory. The contents of ./coverage directory is as follows:

lcov-report (folder)
clover.xml
coverage-final.json
lcov.info

It looks like clover.xml contains code coverage report. There are more details which can be found in lcov-report folder. I've setup the Azure DevOps pipeline as follows for code coverage:

...
- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: '**/junit.xml'

# Publish code coverage results
# Publish Cobertura or JaCoCo code coverage results from a build
- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/clover.xml'

After running the pipeline, Azure DevOps doesn't seem to find the cover.xml file. I get the following error:

##[debug]Result: true
##[debug]Report directory: /home/vsts/work/_temp/cchtml
Reading code coverage summary from '/home/vsts/work/1/s/coverage/clover.xml'
##[warning]No coverage data found. Check the build errors/warnings for more details.
##[debug]Processed: ##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=/home/vsts/work/1/s/coverage/clover.xml;reportdirectory=/home/vsts/work/_temp/cchtml;]

I also tried the following options for summaryFileLocation but all resulted in same error.

'**/coverage/clover.xml'
'$(System.DefaultWorkingDirectory)/**/coverage/clover.xml'

I understand that the format of clover.xml may not be the same as Cobertura or JaCoCo, but at least Azure should be able to locate the file. What I'm missing?

like image 511
Donotalo Avatar asked Sep 14 '25 10:09

Donotalo


1 Answers

I've found a way accidentally.

It looks like Jest can generate cobertura coverage report. It needs to be added in Jest configuration. I've added the following in jest.config.js:

coverageReporters: ['text', 'text-summary', 'clover', 'cobertura']

Jest generated the cobertura coverage file in:

./coverage/cobertura-coverage.xml

Next I modified Azure pipeline file as follows:

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'

After this changes, when I run the pipeline, Azure DevOps can find the file and show coverage report!

like image 124
Donotalo Avatar answered Sep 17 '25 18:09

Donotalo