Sonarqube showing zero coverage

I am using codepipeline for UI(reactJS). Able to see coverage report in codebuild agent but not publishing into sonarqube. I am using below buildspec file,
- npm install
- npm run lint
- npm run test
- npm run build
- npm install -g sonarqube-scanner
- sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=$microserviceName -Dsonar.sources=src -Dsonar.tests=src -Dsonar.language=js -Dsonar.dynamicAnalysis=reuseReports -Dsonar.test.inclusions=src/*.test.js,src/App.js,src/index.js -Dsonar.coverage.exclusions=logo.svg,setupTests.js,index.css,App.css -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info

below is the package file:
“dependencies”: {
@testing-library/jest-dom”: “^5.11.10”,
@testing-library/react”: “^11.2.5”,
@testing-library/user-event”: “^12.8.3”,
“cross-env”: “^7.0.3”,
“eslint”: “^7.22.0”,
“react”: “^17.0.2”,
“react-dom”: “^17.0.2”,
“react-scripts”: “4.0.3”,
“web-vitals”: “^1.1.1”,
“jest-sonar-reporter”: “^2.0.0”
},
“scripts”: {
“start”: “react-scripts start”,
“build”: “react-scripts build”,
“test”: “cross-env CI=true react-scripts test --env=jsdom --coverage --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js”,
“sonar”: “react-scripts test --coverage --watchAll false --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js”,
“eject”: “react-scripts eject”,
“lint”: “eslint ./src”
},
“jestSonar”: {
“sonar85x”: true,
“reportPath”: “coverage”,
“reportFile”: “test-report.xml”,
“indent”: 4
},

What Im missing? can someone help me on this

Hi Venkata

Can you please post the logs from codepipeline? Additional info like SonarQube version would be helpful too.

Thanks

using sonar 8.5+ version.

Please find the below logs.
Running command sonar-scanner -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=$microserviceName -Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions=src/*.test.js -Dsonar.coverage.exclusions=src/App.js,src/index.js -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
[07:23:05] Starting analysis…
[07:23:05] Getting info from “package.json” file
[07:23:05] Checking if executable exists: /root/.sonar/native-sonar-scanner/sonar-scanner-4.5.0.2216-linux/bin/sonar-scanner
[07:23:05] Could not find executable in “/root/.sonar/native-sonar-scanner”.
[07:23:05] Proceed with download of the platform binaries for SonarScanner…
[07:23:05] Creating /root/.sonar/native-sonar-scanner
[07:23:05] Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.5.0.2216-linux.zip
[07:23:05] (executable will be saved in cache folder: /root/.sonar/native-sonar-scanner)

INFO: Scanner configuration file: /root/.sonar/native-sonar-scanner/sonar-scanner-4.5.0.2216-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.5.0.2216
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 4.14.219-119.340.amzn1.x86_64 amd64
INFO: User cache: /root/.sonar/cache
INFO: Scanner configuration file: /root/.sonar/native-sonar-scanner/sonar-scanner-4.5.0.2216-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.5.1
INFO: Default locale: “en_US”, source code encoding: “US-ASCII” (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=152ms
INFO: Server id: DDAD16F2-AXiC40SaDztiDtj48KFP
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=89ms
INFO: Load/download plugins (done) | time=4545ms
INFO: Process project properties
INFO: Process project properties (done) | time=8ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: oom-ui-platform-trial
INFO: Base dir: *****/oom-ui-platform-trial
INFO: Working dir: /oom-ui-platform-trial/.scannerwork
INFO: Load project settings for component key: ‘oom-ui-platform-trial’
INFO: Load project settings for component key: ‘oom-ui-platform-trial’ (done) | time=68ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=121ms
INFO: Load active rules
INFO: Load active rules (done) | time=1439ms
INFO: Indexing files…
INFO: Project configuration:
INFO: Excluded sources: node_modules/, bower_components/, jspm_packages/, typings/, lib-cov/, coverage/, src/
.test.js
INFO: Included tests: src/
.test.js
INFO: Excluded sources for coverage: src/App.js, src/index.js
INFO: Load project repositories
INFO: Load project repositories (done) | time=63ms
INFO: 7 files indexed
INFO: 7 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for css: Sonar way
INFO: Quality profile for js: Sonar way
INFO: ------------- Run sensors on module oom-ui-platform-trial
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=82ms
INFO: Sensor CSS Metrics [cssfamily]
INFO: Sensor CSS Metrics [cssfamily] (done) | time=59ms
INFO: Sensor CSS Rules [cssfamily]
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Sensor CSS Rules [cssfamily] (done) | time=1422ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
INFO: Sensor JavaScript analysis [javascript]
INFO: 3 source files to be analyzed
INFO: 3/3 source files have been analyzed
INFO: Java-based frontend sensor [javascript]
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/root/.sonar/cache/2fab92be44e07f1d367f891a55258736/sonar-javascript-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: 3 source files to be analyzed
INFO: Java-based frontend sensor [javascript] (done) | time=709ms
INFO: 3/3 source files have been analyzed
INFO: Sensor JavaScript analysis [javascript] (done) | time=3111ms
INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: Analysing [
/coverage/lcov.info]
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=6ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=1ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=3ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=1ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 6 source files to be analyzed
INFO: SCM Publisher 6/6 source files have been analyzed (done) | time=1530ms
INFO: CPD Executor 1 file had no CPD blocks
INFO: CPD Executor Calculating CPD for 2 files
INFO: CPD Executor CPD calculation finished (done) | time=15ms
INFO: Analysis report generated in 141ms, dir size=87 KB
INFO: Analysis report compressed in 25ms, zip size=17 KB
INFO: Analysis report uploaded in 117ms
INFO: ANALYSIS SUCCESSFUL, you can browse ***/dashboard?id=oom-ui-platform-trial
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report

can someone reply. still issue is open

Hi Venkata

You have provide -Dsonar.sources=src -Dsonar.tests=src in that situation you will not get coverage as it is all flaged as test code. So try to specify each test directory separately or drop the sonar.tests parameter.

See the doc for more info.
https://docs.sonarqube.org/latest/analysis/analysis-parameters/