简体   繁体   中英

SonarQube Javascript: how to show unit tests dashboard with mocha

I am learning how to integrate sonarqube with a NodeJS project, so far it has been working fine but the dashboard has the unit tests measure missing. The runner being used for testing the project is mocha and i've been using nyc to generate a lcov file so the coverage measures are displayed in sonar, however i am not able to make the unit test measure to display even when i've tried many mocha reporters, for now i am trying mocha-junit-reporter in order to create a XML file.

For the xml to be generated in coverage/ this is the command i've run:

MOCHA_FILE=./coverage/file.xml npx mocha test/**/*.js --reporter mocha-junit-reporter

The scanner is being used by Jenkins and it has these properties:

sonar.projectKey=node-user-data
sonar.projectName="User Data"
sonar.projectVersion=1.0
sonar.baseProjectDir=${workspace}
sonar.sources=${workspace}/classes
sonar.tests=${workspace}/test
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.exclusions=node_modules/**
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.javascript.jstestdriver.reportsPath=${workspace}/coverage/file.xml

I have also tried removing the xml file in reportsPath parameter as i have readed it has to point to directory where the xml file is but still no avail.

Any help on how i could display the unit tests number in dashboard is appreciated

sonar.javascript.jstestdriver.reportsPath is deprecated since a long time. You should use generic report import: https://docs.sonarqube.org/display/SONAR/Generic+Test+Data

To convert to generic format use something like this https://www.npmjs.com/package/mocha-sonarqube-reporter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM