Reputation: 287
I am using SonarQube 6.5, And trying import lcov.info file for code coverage using sonar.javascript.lcov.reportPaths property.
My build is done using Jenkins. code is deployed and tested at /path/to/Deploydirectory/parent-project1/project1/ and reports are generated in jenkins workspace /path/to/jenkins/workspace/BUILD_DEPLOY/parent-project1/project1/coverage.
I am using istanbul for code coverage as
"scripts": {
"coverage": "./node_modules/.bin/istanbul cover
node_modules/mocha/bin/_mocha --dir=/path/to/jenkins/workspace/BUILD_DEPLOY/parent-project1/project1/coverage"
},
lcov.info are generated as below
TN:
SF:/path/to/Deploydirectory/project1/package/plugins/file1.js
FN:11,convetUTCtoLocal
FN:17,customCallback
FN:26,(anonymous_3)
FN:50,(anonymous_4)
FN:68,(anonymous_5)
FN:95,(anonymous_6)
......
On SonarQube getting error
Could not resolve 2 file paths in [/path/to/jenkins/workspace/BUILD_DEPLOY/parent-project1/project1/coverage/lcov.info, /path/to/jenkins/workspace/BUILD_DEPLOY/parent-project2/project2/coverage/lcov.info], first unresolved path: /path/to/Deploydirectory/parent-project1/project1/file1.js
sonrQube config
sonar.inclusions=**/*.js
sonar.scm.disabled=true
sonar.sources=$WORKSPACE
sonar.java.binaries=$WORKSPACE
sonar.projectBaseDir=/path/to
sonar.javascript.lcov.reportPaths=
/path/to/jenkins/workspace/BUILD_DEPLOY/parent-
project1/project1/coverage/lcov.info,
/path/to/jenkins/workspace/BUILD_DEPLOY/parent-
project2/project2/coverage/lcov.info
sonar.sourceEncoding=UTF-8
Upvotes: 2
Views: 2456
Reputation: 395
You may have some property in your sonar-project.properties
that's conflicting with reporting, possibly a pathing issue?
Having generated the lcov.info
file, and telling sonar-scanner where it is via sonar.javascript.lcov.reportPaths
(a comma-separated list) will upload your coverage correctly.
Considering the case where coverage is generated with nyc
NPM module (or istanbul
in your case, as long as the lcov file is generated), the coverage script and the sonar config would be the following:
package.json
:
"scripts": {
"coverage": "nyc npm test",
"test": "mocha tests/unit/*.js"
},
sonar-project.properties
:
sonar.host.url=https://sonarqube.server
sonar.scm.disabled=true
sonar.projectKey=my-app
sonar.projectName=My App
sonar.projectVersion=1.0
sonar.language=js
sonar.sources=src
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.eslint.reportPaths=eslint-report.json
Upvotes: 0