6

Issue: Sonarqube coverage is 0% after i configured karma and sonar.

Arch: Application use Angular7 and Node v8.14, the integrated Sonarqube is the latest version and JDK is java 11.

Issue Desc: these are my local environment, after i configured and run coverage and sonar, karma coverage is 35% but in sonar it's still 0%.

Please see my code as below:

package.json:

  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "sonar": "sonar-scanner"
  },
  "dependencies": {
     ...
     "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "puppeteer": "^2.0.1"
   },
  "devDependencies": {
     ...
     "sonarqube-scanner": "^2.6.0",
  }

sonar-project.properties:

sonar.projectKey=aaa
sonar.projectName=AAA
sonar.projectVersion=1.0.0
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.test.reportPath=./test-results.xml
sonar.language=ts
sonar.exclusions=**/node_modules/**
sonar.tests=src
sonar.typescript.lcov.reportPaths=coverage/lcov.info
sonar.test.inclusions=**/*.spec.ts

karma.conf.js:

    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    // browsers: ['ChromeHeadless'],
    // singleRun: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
  ...

Karma Coverage enter image description here

calss structure

enter image description here

sonar coverage enter image description here

Rollsbean
  • 715
  • 2
  • 11
  • 31

2 Answers2

1

I had the same issue, but were able to find the solution. It turns out that beginning with SonarQube 8.2 they no longer differentiate between JavaScript and TypeScript in their properties. To specify the path for the line coverage report you now always have to use:

sonar.javascript.lcov.reportPaths=<your path here>

Most tutorials aren't up to date on this one, unfortunately.

DocBrown
  • 11
  • 1
0

I don't know if is same issue, but this work for me.

In sonar-project.properties file:

sonar.typescript.lcov.reportPaths=coverage/{name_proyect}/lcov.info

Where name_proyect: is path where I build my project.

Mario Villanueva
  • 327
  • 3
  • 10