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:

TN:
SF:src/lib/services/index.ts
FN:5,getPartners
FN:9,get
FNF:2
FNH:2
FNDA:1,getPartners
FNDA:1,get
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:9,1
LF:9
LH:9
BRDA:5,0,0,1
BRDA:9,1,0,1
BRF:2
BRH:2
end_of_record

When using lcov viewer (https://lcov-viewer.netlify.app/)


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: [
      ...configDefaults.exclude,
      'packages/template/*',
      '*.{config,options}.*',
      '**/*model*',
    ],
    environment: 'jsdom',
    globals: true,
    coverage: {
      provider: 'c8',
      all: true,
      reporter: ['json', 'lcov', 'text', 'text-summary', 'html'],
      exclude: [
        '*.{config,options}.*',
        'coverage/**',
        '**/*.spec.*',
        '.nuxt/**',
        'dist/**',
        '.*.{js|ts}',
        'configure-webpack.js',
        '**/*.d.*',
        '**/*/enums/*',
        '**/*model*',
        '**/*model*',
        'src/index.ts',
        'src/lib/index.ts',
      ],
      reportsDirectory:
        '../../../../coverage/libs/customer',
    },
    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 https://sonarcloud.io/project/overview?id=vue-vitest-ts
git repo GitHub - schirrel/vue-vitest-ts-coverage-problems


Hey there.

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

src/helpers/index.ts
src/App.vue

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