Karma code coverage doesn't show in Sonarqube
Asked Answered
N

2

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

Nomology answered 29/4, 2020 at 3:9 Comment(2)
were you ever able to find a solution for this? I'm facing the same problem todayKilgore
same problem, anyone here found a solution? @NerdinTrainingTilley
L
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.

Legman answered 21/1, 2022 at 15:24 Comment(0)
S
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.

Stablish answered 21/10, 2021 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.