Search code examples
javascriptsonarqubesonar-runneristanbul

SONAR unable to publish code coverage for istanbul reports


I am currently using Sonar Qube version 6.1 along with Istanbul as a test runner. I see that the lcov.info file is generated. Below is how it looks:

TN:
SF:/opt/jenkins_build/workspace/SONAR_QUBE_IMPLEMENTATIONS/Myapp-
CI/public/elements/asset-browser/asset-browser.html
FNF:0
FNH:0
DA:28,2
LF:1
LH:1
BRF:0
BRH:0
end_of_record
TN:
SF:/opt/jenkins_build/workspace/SONAR_QUBE_IMPLEMENTATIONS/Myapp-
CI/public/elements/views/reports-view.html
FNF:0
FNH:0
DA:15,1
LF:1
LH:1
BRF:0
BRH:0
end_of_record

In the logs I see below error, when I run the sonar runner.

02:18:20.322 INFO  - Unit Test Coverage Sensor is started
02:18:20.323 INFO  - 1/1 source files have been analyzed
02:18:20.325 INFO  - Analysing 
[/opt/jenkins_build/workspace/SONAR_QUBE_IMPLEMENTATIONS/Myapp-
CI/coverage/lcov.info]
02:18:20.348 WARN  - Could not resolve 2 file paths in 
[/opt/jenkins_build/workspace/SONAR_QUBE_IMPLEMENTATIONS/Myapp-
CI/coverage/lcov.info], first unresolved path: 
/opt/jenkins_build/workspace/SONAR_QUBE_IMPLEMENTATIONS/Myapp-
CI/public/elements/asset-browser/asset-browser.html

This is how my sonar.project.properties look:

#-- SonarQube server URL
sonar.host.url=http://localhost:9000/sonar

#-- Required Project Properties
sonar.projectKey=Reporting-App
sonar.projectName=Reporting-App
sonar.projectVersion=1.0
sonar.sources=public

#-- Sonar Quality Profile
javascript.sonar.language=js

#-- Report generated in form of
sonar.issuesReport.html.enable=true
sonar.issuesReport.console.enable=true

#-- Specify if any files to include or exclude
sonar.exclusions=tasks/***,public/bower_components/**,public/_index-inline-
loading-script.js

# Encoding of the source files
sonar.sourceEncoding=UTF-8

#-- Coverage Reports
#sonar.javascript.lcov.reportPaths=coverage/lcov.info,coverage/lcov/lcov.info
sonar.javascript.lcov.reportPath=coverage/lcov.info

The sonar dashboard shows O% coverage for my App. However, when I hit the asset browser.html and reports.html from jenkins, it has the correct coverage percentage. This one has been a nightmare for me so far.


Solution

  • Your report contains only HTML files, which are not considered as JavaScript files. Only javascript files' coverage is imported with property sonar.javascript.lcov.reportPath