Sonar Typescript Coverage Failing

  • Local Sonar Version - Community Edition Version 7.9.2 (build 30863)
  • Hosted Sonar Version - Version 7.0 (build 36138)
  • Sonar Scanner 4.0.0.1744
  • SonarJS/TS - 6.2 / 2.1
  • Sonar NPM Module - 2.5.0

Between March 6th and Today, our pipeline is no longer reporting code coverage - either in full or on new code.

We have a multi-module setup for an Angular project that has a root properties file and uses the multi-module for each library and app shipped from this repo

Nothing has changed in our configuration files, but we are now observing the following message in the sonar output:

INFO: Analysing [/Users/tpiper1/work/frontend/core-frontend/libs/core/auth-core/../../../coverage/libs/core/auth-core/lcov.info]
WARN: Could not resolve 7 file paths in [/Users/tpiper1/work/frontend/core-frontend/libs/core/auth-core/../../../coverage/libs/core/auth-core/lcov.info], first unresolved path: libs/core/auth-core/src/lib/auth-core.module.ts

The main sonar file is:

sonar.projectKey=core:frontend
sonar.projectName=Core Frontend
sonar.exclusions=**/node_modules/**/*, **/*.spec.ts, **/*.e2e.ts, **/environments/**/*, **/*.routes.ts, **/main.ts, **/test-setup.ts, **/polyfills.ts
sonar.test.inclusions=**/*.spec.ts
sonar.sourceEncoding=UTF-8
sonar.typescript.tsconfigPath=tsconfig.json
sonar.host.url=http://localhost:9000 # Normally the remote URL
sonar.modules=api-core,auth-core,utils-core,demo-app
api-core.sonar.projectBaseDir=libs/core/api-core
auth-core.sonar.projectBaseDir=libs/core/auth-core
utils-core.sonar.projectBaseDir=libs/core/utils-core
demo-app.sonar.projectBaseDir=apps/demo/demo-app

An example submodule would be:

sonar.projectName=Utilities Core
sonar.sources=src
sonar.tests=src
sonar.typescript.lcov.reportPaths=../../../coverage/libs/core/utils-core/lcov.info

If I change to sonar.typescript.lcov.reportPaths to sonar.javascript.lcov.reportPaths I don’t get the above issue, but there is still zero coverage.

INFO: Sensor SonarTS [typescript]
INFO: Analyzing 11 typescript file(s) with the following configuration file 
/Users/tpiper1/work/frontend/core-frontend/libs/core/auth-core/tsconfig.json
INFO: 11 files analyzed out of 11
INFO: Sensor SonarTS [typescript] (done) | time=3634ms

Current

Previous:

Additionally, I’ve since tried updating to the latest SonarQube locally to 8.2, SonarScanner 4.3.0.2102 and with the newer settings it’s still giving issues.

Here is the verbose log output from running:

output.log.txt (105.7 KB)

I’ve also tried older versions of SonarJS/TS jars within my local scanner, I can confirm they are the versions loaded - but no combination seems to want to display any coverage data.

OK! So I’ve been able to confirm with the following settings:

SonarQube 8.20.32929 Community Edition
SonarQube Scanner 4.0.0.1744 (installed via sonarqube-scanner npm module)
Java 11.0.3 AdoptOpenJDK (64-bit)
Mac OS X 10.14.6 x86_64

If I manually go to the lcov.info file and make the SF: paths absolute then it reports coverage! It seems to be a problem with relative paths, which suggests a regression of 49f34ea (Release 5.2.1) in the SonarJS plugin.


Hi @tanepiper, what exactly did you do? I am having the same issue. SonarJS plugin is currently 5.2.1. Thank you in advance!

Hello,

@tanepiper
Can you provide a reproducer of a multi-modules project with the coverage files, sonar-project.properties files so we can scan it locally and understand better the problem?

@faye
Can you upgrade to SonarJS 6.2 and if you still have the problem, provide a reproducer?

Thanks
Alex

@Alexandre_Gigleux, hi. I’ve already upgraded to SonarJS v6.2. But I’m still having the same issue.

I have this WARN message:
04:15:09.071 WARN: No coverage information will be saved because all LCOV files cannot be found.

@faye I manually edited the lcov file to have an absolute path and it picked up the files.

@Alexandre_Gigleux

What I could do is provide a private copy of the repo I have set up already if that helps, but I’ve already raised a bug over at github and I think I’ve identified the issue and it’s consistently reproducible.

What’s weird is it was working, then it wasn’t - I can only think that maybe somehow we had a copy of the plugin from before 5.2.1 was released, and then it got upgraded (I’m not in control of our Sonar so I have no way to tell)

@tanepiper That would help if you could provide the access to your repo so I can reproduce the problem locally. My GitHub account is agigleux

OK I’ve uploaded it to a private repo on GitHub for you to access

Hello,

I exchanged with Tane privately and thanks to the access to his repo, I managed to reproduce the problem.

The root cause is the use of the deprecated and removed “modules” features (this concept was dropped with SQ 7.6 - MMF-365). In the past, it was required to configure sonar.modules property on the root sonar-project.properties and then to provide a sonar-project.properties per module. This is no longer required and the entire configuration should be simplified

You need to provide only 1 sonar-project.properties at the root of your project and provide only 1 entry sonar.javascript.lcov.reportPaths listing all the coverage files with paths relative to the root of your project. That’s it and other sonar-project.properties must be removed.

Example:

sonar.javascript.lcov.reportPaths=./coverage/core/api/lcov.info,./coverage/core/front-end/lcov.info

Alex