Typescript coverage report- coverage for some .ts files shown as zero coverage

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Scanner 4.2.0.1873, SonarQube server 8.0.0

Coverage is 100% for the files at location src/routes/alert-message.route.ts

Whereas ‘0’ coverage for files under src/test/unit/routes/alert-message-route.test.ts.

My sonar settings are

sonar.sources=.

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.test.inclusions=[’.spec.ts’,’.test.ts’,’//*.spec.ts’,’//.test.ts’,’///.test.ts’,‘test/**/*.ts’]

exclude some files and folders (typically dependencies)

sonar.exclusions=[’.js’,’**/.spec.ts’,’.spec.ts’,’**/.test.ts’,’.test.ts’,'node_modules /**/’]

Please do the needful

Hello,

I believe you do a type while configuring which files are considered as main and which files are considered as test files.
Only main files should expect to receive coverage data and by default SonarQube will consider that a file where no coverage data were given is covered at 0%. This explain why you see 0% on some test files.
Once these files will be correctly considered as test files, no coverage data will be expected on them.

Can you share your entire sonar-project.properties (formatted as code in this forum) and a screenshot of where you see this “0” coverage?

Thanks

Note: make sure to use the latest version of SonarQube (8.2 as of now) and the latest version of SonarJS analyzer - 6.2 (which performs the TypeScript analysis) to get the best of what we do.

Change to sonar.typescript.lcov.reportPaths=coverage/lcov.info
javascript > typescript

The same issue on my side. For some files code coverage created with LCOV is not shown in SonarQube as it’s visible in the LCOV reports.

Zrzut ekranu 2023-09-7 o 09.42.07

SonarQube version: 9.9.1 (build 69595)
sonarqube-scanner 3.1.0

In the project I have defined:

  • sonar.sources
  • sonar.javascript.lcov.reportPaths

No exclusions are defined, default ones are used:
Excluded sources: node_modules/, bower_components/, jspm_packages/, typings/, lib-cov/**

Hello @mrzepinski,
Did you get a resolution for this as I face exactly the same problem?

Nope, still an issue