Unable to get code coverage for javascript

I am trying to run sonar analysis for java script project and I am getting zero coverage. Below is the log for sonar analysis. Not sure why java script project is not giving any code coverage.

02:23:25  > cls-global@ sonar /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global
02:23:25  > node ./node_modules/gulp/bin/gulp
02:23:25  
02:23:26  [06:23:26] Using gulpfile /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/gulpfile.js
02:23:26  [06:23:26] Starting 'default'...
02:23:26  [06:23:26] Starting SonarQube analysis...
02:23:26  [06:23:26] Getting info from "package.json" file
02:23:26  [06:23:26] Checking if executable exists: /root/.sonar/native-sonar-scanner/sonar-scanner-3.3.0.1492-linux/bin/sonar-scanner
02:23:26  [06:23:26] Could not find executable in "/root/.sonar/native-sonar-scanner".
02:23:26  [06:23:26] Proceed with download of the platform binaries for SonarQube Scanner...
02:23:26  [06:23:26] Creating /root/.sonar/native-sonar-scanner
02:23:26  [06:23:26] Downloading from https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
02:23:26  [06:23:26] (executable will be saved in cache folder: /root/.sonar/native-sonar-scanner)
02:23:30  
02:23:33  INFO: Scanner configuration file: /root/.sonar/native-sonar-scanner/sonar-scanner-3.3.0.1492-linux/conf/sonar-scanner.properties
02:23:33  INFO: Project root configuration file: NONE
02:23:33  INFO: SonarQube Scanner 3.3.0.1492
02:23:33  INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
02:23:33  INFO: Linux 4.4.0-148-generic amd64
02:23:33  INFO: User cache: /root/.sonar/cache
02:23:35  INFO: SonarQube server 7.6.0
02:23:35  INFO: Default locale: "en_US", source code encoding: "US-ASCII" (analysis is platform dependent)
02:23:35  INFO: Load global settings
02:23:35  INFO: Load global settings (done) | time=216ms
02:23:35  INFO: Server id: B1569A4A-AWmi4uq-naChzLef8Wdp
02:23:35  INFO: User cache: /root/.sonar/cache
02:23:35  INFO: Load/download plugins
02:23:35  INFO: Load plugins index
02:23:35  INFO: Load plugins index (done) | time=66ms
02:23:42  INFO: Load/download plugins (done) | time=6177ms
02:23:42  INFO: Loaded core extensions: branch-scanner
02:23:43  INFO: Process project properties
02:23:43  INFO: Execute project builders
02:23:43  INFO: Execute project builders (done) | time=5ms
02:23:43  INFO: Project key: cls2-dev-sq
02:23:43  INFO: Base dir: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global
02:23:43  INFO: Working dir: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/.scannerwork
02:23:43  INFO: Load project settings
02:23:43  INFO: Load project settings (done) | time=38ms
02:23:43  INFO: Load project branches
02:23:43  INFO: Load project branches (done) | time=37ms
02:23:43  INFO: Load project pull requests
02:23:43  INFO: Load project pull requests (done) | time=29ms
02:23:43  INFO: Load branch configuration
02:23:43  INFO: Load branch configuration (done) | time=3ms
02:23:43  INFO: Load project repositories
02:23:43  INFO: Load project repositories (done) | time=76ms
02:23:43  INFO: Load quality profiles
02:23:43  INFO: Load quality profiles (done) | time=52ms
02:23:43  INFO: Load active rules
02:23:44  INFO: Load active rules (done) | time=1048ms
02:23:44  INFO: Load metrics repository
02:23:44  INFO: Load metrics repository (done) | time=33ms
02:23:44  INFO: Branch name: feature/XHCLOUD-1525, type: short living
02:23:44  INFO: SCM collecting changed files in the branch
02:23:44  WARN: Could not find ref: master in refs/heads or refs/remotes/origin
02:23:44  INFO: SCM collecting changed files in the branch (done) | time=59ms
02:23:44  WARN: Property 'sonar.abap.file.suffixes' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.
02:23:44  INFO: Language is forced to js
02:23:44  INFO: Indexing files...
02:23:44  INFO: Project configuration:
02:23:44  INFO:   Excluded sources: node_modules/**, bower_components/**, jspm_packages/**, typings/**, lib-cov/**
02:23:44  INFO: 4 files indexed
02:23:44  INFO: 0 files ignored because of inclusion/exclusion patterns
02:23:44  INFO: Quality profile for js: Xhome
02:23:44  INFO: ------------- Run sensors on module cls-global
02:23:47  INFO: Sensor JavaXmlSensor [java]
02:23:47  INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
02:23:47  INFO: Sensor HTML [web]
02:23:47  INFO: Sensor HTML [web] (done) | time=12ms
02:23:47  INFO: Sensor JaCoCo XML Report Importer [jacoco]
02:23:47  INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
02:23:47  INFO: Sensor SonarJS [javascript]
02:23:47  INFO: 2 source files to be analyzed
02:23:47  INFO: Sensor SonarJS [javascript] (done) | time=447ms
02:23:47  INFO: Sensor ESLint-based SonarJS [javascript]
02:23:47  INFO: 2/2 source files have been analyzed
02:23:49  INFO: 2 source files to be analyzed
02:23:49  INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=1878ms
02:23:49  INFO: 2/2 source files have been analyzed
02:23:49  INFO: Sensor Zero Coverage Sensor
02:23:49  INFO: Sensor Zero Coverage Sensor (done) | time=15ms
02:23:49  INFO: Sensor JavaSecuritySensor [security]
02:23:49  INFO: Reading UCFGs from: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/.scannerwork/ucfg2/java
02:23:49  INFO: 06:23:49.527 Building Type propagation graph
02:23:49  INFO: 06:23:49.538 Running Tarjan on 0 nodes
02:23:49  INFO: 06:23:49.539 Tarjan found 0 components
02:23:49  INFO: 06:23:49.539 Variable type analysis: done
02:23:49  INFO: UCFGs: 0, excluded: 0, source entrypoints: 0
02:23:49  INFO: No UCFGs have been included for analysis.
02:23:49  INFO: Sensor JavaSecuritySensor [security] (done) | time=24ms
02:23:49  INFO: Sensor CSharpSecuritySensor [security]
02:23:49  INFO: Reading UCFGs from: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/ucfg_cs2
02:23:49  INFO: 06:23:49.541 Building Type propagation graph
02:23:49  INFO: 06:23:49.541 Running Tarjan on 0 nodes
02:23:49  INFO: 06:23:49.542 Tarjan found 0 components
02:23:49  INFO: 06:23:49.542 Variable type analysis: done
02:23:49  INFO: UCFGs: 0, excluded: 0, source entrypoints: 0
02:23:49  INFO: No UCFGs have been included for analysis.
02:23:49  INFO: Sensor CSharpSecuritySensor [security] (done) | time=1ms
02:23:49  INFO: ------------- Run sensors on project
02:23:49  INFO: SCM provider for this project is: git
02:23:49  INFO: 1 files to be analyzed
02:23:49  INFO: 1/1 files analyzed
02:23:49  INFO: Calculating CPD for 2 files
02:23:49  INFO: CPD calculation finished
02:23:49  INFO: SCM writing changed lines
02:23:49  WARN: Could not find ref: master in refs/heads or refs/remotes/origin
02:23:49  INFO: SCM writing changed lines (done) | time=2ms
02:23:49  INFO: Analysis report generated in 113ms, dir size=120 KB
02:23:50  INFO: Analysis report compressed in 10ms, zip size=21 KB
02:23:50  INFO: Analysis report uploaded in 57ms

I don’t see anything related to coverage in the logs. Do you provide coverage report? See docs

Yes. I did add this coverge report sonar.javascript.lcov.reportPaths to my project .

Are you sure? How do you launch analysis? what is in your properties file?
If property would be there, you would see “SonarJS Coverage” sensor in the logs.

Below is the log for the sonarJS Coverage.

02:23:47  INFO: 2 source files to be analyzed
02:23:47  INFO: Sensor SonarJS [javascript] (done) | time=447ms
02:23:47  INFO: Sensor ESLint-based SonarJS [javascript]
02:23:47  INFO: 2/2 source files have been analyzed
02:23:49  INFO: 2 source files to be analyzed
02:23:49  INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=1878ms
02:23:49  INFO: 2/2 source files have been analyzed
02:23:49  INFO: Sensor Zero Coverage Sensor
02:23:49  INFO: Sensor Zero Coverage Sensor (done) | time=15ms
02:23:49  INFO: Sensor JavaSecuritySensor [security]
02:23:49  INFO: Reading UCFGs from: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/.scannerwork/ucfg2/java
02:23:49  INFO: 06:23:49.527 Building Type propagation graph
02:23:49  INFO: 06:23:49.538 Running Tarjan on 0 nodes
02:23:49  INFO: 06:23:49.539 Tarjan found 0 components
02:23:49  INFO: 06:23:49.539 Variable type analysis: done
02:23:49  INFO: UCFGs: 0, excluded: 0, source entrypoints: 0
02:23:49  INFO: No UCFGs have been included for analysis.
02:23:49  INFO: Sensor JavaSecuritySensor [security] (done) | time=24ms
02:23:49  INFO: Sensor CSharpSecuritySensor [security]
02:23:49  INFO: Reading UCFGs from: /home/jenkins/workspace/ion-service_feature_XHCLOUD-1525/cls-global/ucfg_cs2
02:23:49  INFO: 06:23:49.541 Building Type propagation graph
02:23:49  INFO: 06:23:49.541 Running Tarjan on 0 nodes
02:23:49  INFO: 06:23:49.542 Tarjan found 0 components
02:23:49  INFO: 06:23:49.542 Variable type analysis: done
02:23:49  INFO: UCFGs: 0, excluded: 0, source entrypoints: 0```

Here is the sonar properties file

const sonarqubeScanner = require('sonarqube-scanner');

gulp.task('default', function(callback) {
    sonarqubeScanner({
        serverUrl: "https://sonarqube.xxxxxxxx",
        token: process.env.SONARQUBE_CLS_GLOBAL_TOKEN,
        options: {
            "sonar.projectKey": "cls2-dev-sq",
            "sonar.sources": "./src/handlers",
            "sonar.tests": "./test/integration/handlers",
            "sonar.language": "js",
            "sonar.dynamicAnalysis": "reuseReports",
            "sonar.javascript.jstests.reportsPath": "test",
            "sonar.javascript.lcov.reportPath": "test/coverage/lcov.info"
        }
    }, callback);
});

Hello @lakshmi1,

From the properties you’ve given, there’s a s missing to the property name.
It should be "sonar.javascript.lcov.reportPaths": "test/coverage/lcov.info", instead of "sonar.javascript.lcov.reportPath": "test/coverage/lcov.info". Fixing the typo should fix your problem.

Best,
-Chris