Sonar wrong interpretations of lcov generated accusing no coverage and looking at wrong file

Hi i have a single module with this structure:

  • src/
  • index.ts ← only exports
    • lib/
      • index.ts ← only exports
      • services/
        • test
          • index.ts ← test file
        • index.ts ← only with development

only the service/index.ts file has code and it has unit test on the test folder.
I am using vitest and when running test localy it shows the coverage:

The lcov file generated report:


When using lcov viewer (

it matches the coverage from the terminal.
I had src/index.ts and src/lib/index.ts on exclusion property on the coverage prop on vitest.
But on sonar platform it only shows the src/lib/index.ts as new code and also sonar requires to add coverate to export * from

The project is correct configured for typescript and start to present this behavior on 20/03 whithout ani change on our sonar project or in our sonar config inside the project folder.

my vitest config:

import { fileURLToPath, URL } from 'node:url'

import { createVuePlugin as vue } from 'vite-plugin-vue2'
import { configDefaults, defineConfig } from 'vitest/config'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
  test: {
    passWithNoTests: true,
    exclude: [
    environment: 'jsdom',
    globals: true,
    coverage: {
      provider: 'c8',
      all: true,
      reporter: ['json', 'lcov', 'text', 'text-summary', 'html'],
      exclude: [
    deps: {
      external: ['**/node_modules/**', '**/dist/**'],
    include: ['**/*.spec.{js,ts,vue}'],

Hey there.

You’ll have to set those exclusions as coverage exclusions as well, which means duplicating what you’ve set in your vitest config.

Hi Colin, thanks for the response.
Even setting the exclusion for sonar, the file that have test (src/lib/services/index.ts) still dont show up on sonar :frowning:

Colin, i’ve create a reproduction case for further info and analysis:
sonar cloud
git repo GitHub - schirrel/vue-vitest-ts-coverage-problems

Hey there.

Both of those code files look different on your project now.


Are you still facing an issue?

Hi Colin, after the message i;'e add a plain test of app.vue

Strange as it is somethings change, but dont got less strange, the export files started to shows as coverage once i add test for App.vue, it dont quite make sense.

But another strange stuff starts to show:

  • App.vue now has a coverage but it shows a </div> as uncoverade line (here)
  • HelloWord.vue has import vue line as uncovered (here)
  • main.ts has uncoverage import lines (here)

as far as i read on sonar config, once using TS and configure as "sourceMap": true it handle the import and export lines, avoid to be required of coverage.
Is there any setup for sonar to ignore import/export lines?

I think you need to refer to your LCOV reports to see if they to refer to these lines as being unconverd.

And if this file is referenced in the coverage report at all

SonarCloud relies on the coverage report to decide which lines can/can’t be covered by tests – if the file is absent, it assumes there is no coverage (and if a file should be excluded from coverage entirely, that’s where coverage exclusions come into play)

Hi Colin, thanks for you time.
I’ve open a issue on vitest and also there a problem with c8 coverage reportes/
So not at all about sonar
sorry for this

1 Like

Hello, did you manage to find a solution for the import problem?

Hello, did you find something about that? I have the same problem here, with my backend in nodejs, the vitest coverage get me the 90% but when I send to the sonar scanner, sonar qube get me the 14%