Coverage not calculated when merged to gitlab

Hi, I’m trying to get coverage for my Angular 11 mono-repo project on gitlab + AWS environment.
It has combination of karma + jest test and the SonarQube server version is 9.5.0.56709

While I can see my coverage for the project before merge, my coverage is 0% as no lcov file is found.
This is the log when I merge

INFO: Sensor TypeScript analysis [javascript] (done) | time=232156ms
INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: No LCOV files were found using coverage/**/lcov.info
WARN: No coverage information will be saved because all LCOV files cannot be found.
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=835ms

and this is the merge request pipeline log (and I get the correct coverage)

INFO: Sensor JavaScript analysis [javascript]
INFO: Deploying custom rules bundle jar:file:/root/.sonar/cache/06b160cbad8e9f8df7328b1a2c5a0afe/sonar-securityjsfrontend-plugin.jar!/js-vulnerabilities-rules-1.0.0.tgz to /builds/YECb221b/0/project/.scannerwork/.sonartmp/eslint-bridge-bundle/package/custom-rules2175062094652070529
INFO: 67 source files to be analyzed
INFO: 67/67 source files have been analyzed
INFO: Sensor JavaScript analysis [javascript] (done) | time=7380ms

Could someone help me to solve this problem? I really don’t understand why I cannot get lcov files only when merging the project while I’m getting it for merge request.

my gitlab script

  - npm install -g sonarqube-scanner
  script:
  - npm run lint:json
  - npm run affected:test
  - sonar-scanner -Dproject.settings=sonar-project.properties -Dsonar.host.url=$SONAR_HOST_URL
    -Dsonar.login=$SONAR_TOKEN -Dsonar.qualitygate.wait=true -Dsonar.projectKey="project"

my sonar-project.properties

sonar.projectKey=project
sonar.projectName=project
sonar.projectVersion=1.0
sonar.sources=apps/,libs/
sonar.exclusions=**/node_modules/**,**/*.spec.ts
sonar.sourceEncoding=UTF-8
sonar.tests=apps/,libs/
sonar.test.inclusions=**/*.spec.ts
sonar.coverage.exclusions=**/*.mock.ts,**/*.js
sonar.javascript.lcov.reportPaths=coverage/**/lcov.info
sonar.typescript.eslint.reportPaths=linter.*.issues.json

Thanks!

What do these same log lines say when you run a merge request analysis? (not that Sensor JavaScript analysis [javascript] is different than Sensor JavaScript/TypeScript Coverage [javascript])

ah, good question! found JavaScript/TypeScript Coverage when merging request is actually the same.
Do you have any idea how to solve this problem?

INFO: Sensor TypeScript analysis [javascript] (done) | time=240761ms
INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: No LCOV files were found using coverage/**/lcov.info
WARN: No coverage information will be saved because all LCOV files cannot be found.
INFO: Sensor JavaScript/TypeScript Coverage [javascript] (done) | time=866ms

Found the cause of the problem: NX. It was because of nx:affected in my case. It simply does not run test when merged so no LCOV files created. I replaced it to nx run-many --target=test --all and it runs test when merged. now everything works fine.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.