SonarSource / SonarJS

SonarSource Static Analyzer for JavaScript and TypeScript
https://community.sonarsource.com/
GNU Lesser General Public License v3.0
1.05k stars 183 forks source link

Unit test result does not show on SonarQube Dashboard for nodejs #751

Closed SudeepParajuli closed 7 years ago

SudeepParajuli commented 7 years ago

SonarQube Version : 6.0.0 SonarJS: 2.17.0.3154

Issue

The main aim is to display coverage report and the unit test result in SonarQube dashboard. Though I am able to get the coverage report but not able to get the unit test result in SonarQube dashboard . I have been using the mocha for unit testing and istanbul nyc for code coverage. The report generated by mocha is in xml format using the package mocha-sonar-reporter and the coverage report is in lcov format .

_Sonar.Property File

sonar.projectKey=unittest sonar.projectName=unittest sonar.projectVersion=1.0.0

sonar.sources=src/ sonar.tests=test/

sonar.language=js sonar.sourceEncoding=UTF-8 sonar.javascript.jstestdriver.reportsPath=/home/jenkinsbot/workspace/devops_stuffs/reports sonar.javascript.lcov.reportPath=/home/jenkinsbot/workspace/devopsstuffs/reports/lcov.info

SonarQube log :

_[Pipeline] wrap Injecting SonarQube environment variables using the configuration: Sonar(dk.147) [Pipeline] { [Pipeline] sh [e_feature_COS-239-unit-test-P23YKERWYLNSD6K3ISKUHA5NSJTRN6K7DRJGKI5QLG6LTD3HHOPA] Running shell script

screen shot 2017-09-20 at 11 33 39 am

vilchik-elena commented 7 years ago

Hi,

Unit test results import is not provided anymore by SonarJS. For that you should use SQ's native feature Generic Test Data (since SQ 6.2). If you use SQ < 6.2 use this plugin https://docs.sonarqube.org/display/PLUG/Generic+Test+Coverage.

SudeepParajuli commented 7 years ago

Since my SQ < 6.2 I tried the Generic Test Coverage Plugin with the following changes :

Installed Generic Coverage Plugin 1.2 Edited the sonar.property file with : sonar.genericcoverage.unitTestReportPaths=report

Still I am not able to achieve the unit test result depiction on dashboard.

The XML generated by my mocha-sonar-reporter is in this format :

<testsuite name="Mocha Tests" tests="50" failures="0" errors="0" skipped="0" timestamp="Wed, 20 Sep 2017 04:00:45 GMT" time="3.933">
<testcase classname="app/redux/transaction.spec.js" name="Search actions creates LOCAL_FETCH_SUCCESS when translation fetch done" time="0.01"/>

But for Generic Coverage Plugin it should be in this format :

<unitTest version="1">
  <file path="src/test/java/com/example/MyTestClass.java">
    <testCase name="test1" duration="500"/>
     </testCase>
    </file>
</unitTest>

How could I generate the xml in this supported format with mocha . Any idea @vilchik-elena

vilchik-elena commented 7 years ago

try this https://github.com/pghalliday/mocha-sonar-reporter or this https://github.com/mageddo/mocha-sonar-generic-test-coverage

SudeepParajuli commented 7 years ago

So kind of you . Thank you @vilchik-elena . It worked .

jithuvijayan1992 commented 6 years ago

@vilchik-elena my SQ's version is 6.4 , here i am using mocha for my nodjs project. The code coverage is not getting on the SQ's dashboard, which tool i need to use.

vilchik-elena commented 6 years ago

@jithuvijayan1992 create new ticket, put configuration and logs

vilchik-elena commented 6 years ago

jithuvijayan1992 please create new issue..

kiransterling commented 5 years ago

So kind of you . Thank you @vilchik-elena . It worked .

@SudeepParajuli Which one did you used ?