Tim Heap
Tim Heap

Reputation: 71

SonarQube Lcov.info not found

I'm having an issue with a SonarQube instance. We're printing out lcov information from istanbul, but sonarqube can't find the lcov information to generate code coverage. The project.properties file is here with the lcov information now removed :

sonar.projectKey=*****
sonar.projectName=*****
sonar.projectVersion=1.0
sonar.host.url=***********
sonar.sources=.
sonar.projectBaseDir=./app
sonar.exclusions=**/bower_components/**/*.*,**/vendor/**/*.*
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.verbose=true
sonar.log.level=DEBUG

but the logs from sonarqube say it's still looking for it :

11:19:12.551 INFO: 177/225 files analyzed, current file: /app/app/target/schema/list/target-schema-list-controller_test.js
11:19:15.103 INFO: Unit Test Coverage Sensor is started
11:19:15.103 INFO: 225/225 source files have been analyzed
11:19:15.104 WARN: No coverage information will be saved because LCOV file cannot be found.
11:19:15.104 WARN: Provided LCOV file path: coverage-app/html/lcov.info. Seek file with path: /app/app/coverage-app/html/lcov.info
11:19:15.105 WARN: No coverage information will be saved because all LCOV files cannot be found.
11:19:15.105 INFO: Integration Test Coverage Sensor is started
11:19:15.105 WARN: No coverage information will be saved because LCOV file cannot be found.
11:19:15.106 WARN: Provided LCOV file path: coverage-server/lcov.info. Seek file with path: /app/app/coverage-server/lcov.info
11:19:15.106 WARN: No coverage information will be saved because all LCOV files cannot be found.
11:19:15.106 INFO: Overall Coverage Sensor is started
11:19:15.106 WARN: No coverage information will be saved because LCOV file cannot be found.
11:19:15.106 WARN: Provided LCOV file path: coverage-app/html/lcov.info. Seek file with path: /app/app/coverage-app/html/lcov.info
11:19:15.106 WARN: No coverage information will be saved because LCOV file cannot be found.
11:19:15.107 WARN: Provided LCOV file path: coverage-server/lcov.info. Seek file with path: /app/app/coverage-server/lcov.info
11:19:15.107 WARN: No coverage information will be saved because all LCOV files cannot be found.

If it's not getting the location from the project properties where I'm running the sonarqube program from, then where else can it be reading the config from ?

Upvotes: 4

Views: 15251

Answers (4)

Deepu Reghunath
Deepu Reghunath

Reputation: 9713

Follow the steps.

  1. Add 'lcov' as report type in karma.conf.js

enter image description here

  1. Run the unit test ng test --code-coverage

    It will create a lcov.info file in the coverage folder.

  2. Now run the sonar command as configured in the package.json file

    npm run sonar

enter image description here

Upvotes: 3

Emeric
Emeric

Reputation: 6915

In the case the relative path doesn't work for you, try with the absolute path which was the solution for me.

Dsonar.typescript.lcov.reportPaths=src/coverage/report/lcov.info'

For karma users, do not forget to add the configuration in the coverageReporter which isn't setup by default:

coverageReporter: {
  type: 'lcov' ,
  subdir: 'report'
},

And here is the matching project tree simplified (Angular example):

my-app/
├─ node_modules/
├─ src/
│  ├─ app
│  ├─ assets
│  ├─ coverage
│     ├─ report
│        ├─ lcov-report
│        ├─ lcov.info
│  ├─ environments
│  ├─ karma.conf.js
├─ package.json
├─ README.md
├─ ...

Original answer: https://stackoverflow.com/a/72487459/9753985

Upvotes: 0

mpumi
mpumi

Reputation: 33

Remember the project folder inside the coverage folder

sonar.javascript.lcov.reportPaths=coverage/<project-name>/lcov.info

Upvotes: 1

Uri Stolar
Uri Stolar

Reputation: 180

You should add this setting in your sonar-project.properties file:

sonar.javascript.lcov.reportPaths=path/to/coverage/lcov.info

Also, in some CI tools (in my case is Gitlab CI) you might have to specify that the lcov.info file is an "artifact" so the sonar scanner job doesn't delete it

Upvotes: 9

Related Questions