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