Sonarqube Nodejs test results and code coverage

4,740 views
Skip to first unread message

mobilep...@googlemail.com

unread,
Aug 26, 2016, 6:56:42 PM8/26/16
to SonarQube
I have several JavaScript/NodeJS project besides some Javaprojects. In the Javaprojects it is very easy to see the unit test results and also coverage. For the nodejs project I also tried but all what is described but nothing works. I saw the recommendation is to use the generic coverage plugin. It load the coverage results but does not show the unit test results as in Java.

Does anybody know a way that works with a current sonar Version? Or is there any plan to support it?

Dario Olivini

unread,
Aug 27, 2016, 3:01:12 PM8/27/16
to SonarQube
I use mocha and instambul and i can send the coverage report to sonar. Now I'm an vacation but if you can wait a couple of day I can post the configuration I use.
Till then you can look at grunt-mocha-instambul module and configure the test suite for lcov reporting. I use a directory for sources and one for test it should be easy to configure.
Dario

mobilep...@googlemail.com

unread,
Aug 28, 2016, 7:29:34 AM8/28/16
to SonarQube
Yes dario i can wait. It would help. The coverage (based on lcov file) i already see in sonar but not the testcase count or completion rate.

Freddy Mallet

unread,
Aug 29, 2016, 12:52:46 PM8/29/16
to mobilep...@googlemail.com, SonarQube
Hi @Guys, 

The SonarQube JavaScript plugin natively supports the import of LCOV code coverage reports : http://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import without any need to use the SonarQube Generic Coverage plugin.

Cheers
Freddy

On Sun, Aug 28, 2016 at 1:29 PM mobilephone.dw via SonarQube <sona...@googlegroups.com> wrote:
Yes dario i can wait. It would help. The coverage (based on lcov file) i already see in sonar but not the testcase count or completion rate.

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/3bce7872-b932-4375-b4bc-196dc0ec23bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Freddy MALLET | SonarSource
Product Director & Co-Founder
http://sonarsource.com

Dario Olivini

unread,
Aug 30, 2016, 4:19:36 AM8/30/16
to SonarQube, mobilep...@googlemail.com
Thanks Freddy for the link reference.
As I told I use Mocha+Istanbul for test coverage and instrumentation with Grunt and this module https://github.com/pocesar/grunt-mocha-istanbul.
Here the gruntfile.js part:


// Project configuration.
grunt.config.init({
// MOCHA ISTANBUL Test & Coverage
mocha_istanbul: {
   
default: {
       
// a folder works nicely
        src: ['test/**/*.test.js'],
       
options: {
           
lazy: true,
           
mask: '*.test.js',
           
coverageFolder: 'doc/coverage'
        }
   
}
},
istanbul_check_coverage: {
   
default: {
       
options: {
           
// will check both coverage folders and merge the coverage results
            coverageFolder: 'doc/coverage*',
           
check: {
               
lines: 80,
               
statements: 80
            }
       
}
   
}
}});


and here the part in the sonar-project.properties:

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
sonar.tests=test
sonar.test.exclusions = /test/**/*.*
sonar.javascript.lcov.reportPath = doc/coverage/lcov.info

and the screenshot show you what I get on Sonar. (ps: Sonar version 5.5)

Hope this help.
Cheers
Dario
coverage_example.JPG

Freddy Mallet

unread,
Aug 30, 2016, 9:47:48 AM8/30/16
to Dario Olivini, SonarQube, mobilep...@googlemail.com
Hi Dario, 

According to the SonarQube screenshot, code coverage information is available in SQ, so what's the question ?

Thanks
Freddy

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Freddy Mallet

unread,
Aug 30, 2016, 9:53:43 AM8/30/16
to Dario Olivini, SonarQube, mobilep...@googlemail.com
Sorry I didn't understand that @Dario was in fact sharing his own working solution.
Thanks Dario !

Dario Olivini

unread,
Aug 30, 2016, 9:59:29 AM8/30/16
to Freddy Mallet, SonarQube, mobilep...@googlemail.com
No worries. Thanks also to you!

mobilep...@googlemail.com

unread,
Sep 2, 2016, 8:31:54 AM9/2/16
to SonarQube
Hey Thanks for the Info. As mentioned in my last posts, the nodejs coverage is not the problem at any setup.

I am interested in how can I Import the test results like how many testcases are successful or failing next to the coverage.
In Java projects I see coverage and test results but in nodejs projects I can only see the coverage results.

Pierre-Yves Nicolas

unread,
Sep 5, 2016, 8:05:18 AM9/5/16
to mobilep...@googlemail.com, SonarQube
Hi,

It's hard to help you without any detail.
Can you at least provide the logs of your analysis when you try to import test results with the generic test coverage plugin?

Regards,
Pierre-Yves



--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/aa888e7f-908e-44e3-a576-bfc737da8282%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages