I am using SonarQube for integrating my test in my build process.
I've seen there is a sonnar-scanner npm package but I don't see how it re-use the code coverage from jest/istanbul.
Anyone has experience with SonarQube and istanbul ?
You'll want to create a sonar-project.properties file with relevent content:
```sonar.projectKey=<
sonar.projectName=<
sonar.language=js
sonar.sources=relative/path/to/src
sonar.tests=relative/path/to/tests
sonar.javascript.lcov.reportPaths=path/to/coverage/lcov.info
```
Then you can simply run sonar-scanner directly.
@adam-moss That's correct. Sonarqube is showing the coverage numbers after passing the "sonar.javascript.lcov.reportPaths" argument.
However, many files, which are excluded in the istanbul cover command are also showing up in the sonarqube dashboard. Consequently, the total LOC is higher and coverage number is lower in the sonarqube dashboard.
@biswasaveek Specify any files you want to exclude using sonar.exclusions
E.g. sonar.exclusions=**/*Bean.java,**/*DTO.java
Source: https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus
In my case istanbul is generating a report in html format. How could i convert a html report to lcov file formt ?
Take a look at their github site:
https://github.com/istanbuljs/nyc
From site:
Configuration arguments should be provided prior to the program that nyc is executing. As an example, the following command executes npm test, and indicates to nyc that it should output both an lcov and a text-lcov coverage report.
nyc --reporter=lcov --reporter=text-lcov npm test
In my case istanbul is generating a report in html format. How could i convert a html report to lcov file formt ?
Please follow the below steps to achieve this:
Run the test by running the same command which craigtmoore has mentioned, which is,
nyc --reporter=lcov --reporter=text-lcov npm test
For more details: Please refer (https://github.com/istanbuljs/nyc)
lcov.infoAdd below property in sonar-project.properties file,
sonar.javascript.lcov.reportPaths=app/coverage/lcov.info
Note: For more details please refer
(https://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import)
sonar-scanner command from your project root directory.Result: You must be seeing the code-coverage %age in the generated report by Sonarqube.
Please do comment if still, you're facing the issue.
Thanks
i change sonar-project.properties sonar.javascript.lcov.reportPaths=app/coverage/lcov.info, but its not reflecting in my sonarqube dashboard. can anyone can help me .
Same problem as "Amiya-elear" mentioned.
Try adding the -X flag to the sonar-scanner command it will print debug info which will help you pinpoint why its not picking up your lcov file. You can search the logs with command + f for "lcov" sonar will often times print warnings that it cant find the path to the file which is more than likely the problem
In my case istanbul is generating a report in html format. How could i convert a html report to lcov file formt ?
Please follow the below steps to achieve this:
- Run the test by running the same command which
craigtmoorehas mentioned, which is,
nyc --reporter=lcov --reporter=text-lcov npm test
For more details: Please refer (https://github.com/istanbuljs/nyc)- Once step 1 is completed, you must be seeing a file named as
lcov.info- Add below property in
sonar-project.propertiesfile,
sonar.javascript.lcov.reportPaths=app/coverage/lcov.info
Note: For more details please refer
(https://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import)- Run the
sonar-scannercommand from your project root directory.Result: You must be seeing the code-coverage %age in the generated report by Sonarqube.
Please do comment if still, you're facing the issue.
Thanks
thanks, it help me a lot !
do we need any plugin in sonar to publish instanbul coverage report.
As per my understanding, no additional plugin is required. As I have mentioned above I have followed the same steps to integrate the coverage in the SonarQube app.
Most helpful comment
Please follow the below steps to achieve this:
Run the test by running the same command which
craigtmoorehas mentioned, which is,nyc --reporter=lcov --reporter=text-lcov npm test
For more details: Please refer (https://github.com/istanbuljs/nyc)
lcov.infoAdd below property in
sonar-project.propertiesfile,sonar.javascript.lcov.reportPaths=app/coverage/lcov.info
Note: For more details please refer
(https://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import)
sonar-scannercommand from your project root directory.Result: You must be seeing the code-coverage %age in the generated report by Sonarqube.
Please do comment if still, you're facing the issue.
Thanks