Lcov coverage results not being recognise by Sonar (multiple lcov files)

  • ALM used: GitHub
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI*
  • Scanner command used when applicable (private details masked)
name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  • Languages of the repository: TS, CSS
  • Error observed: coverage in lcov file not being registered

I have two sets of tests that generate coverage data for the same code: unit tests (vitest) and end-to-end tests (playwright). I see Sonar is identifying both files

2024-11-09T22:50:33.8522798Z 22:50:33.851 DEBUG Property sonar.javascript.lcov.reportPaths is used.
2024-11-09T22:50:33.8528362Z 22:50:33.852 DEBUG Using '**/lcov.info' to resolve LCOV files
2024-11-09T22:50:34.8182321Z 22:50:34.817 INFO  Analysing [/github/workspace/coverage/lcov.info, /github/workspace/e2e-coverage/lcov.info]

but the coverage generated by the playwright tests (/github/workspace/e2e-coverage/lcov.info) is not being included in the overall code coverage reported by Sonar.

For example, Sonar is reporting that lines 292 is not covered, but the /github/workspace/e2e-coverage/lcov.info has the following:

TN:
SF:src/app/routes/index.tsx
FN:53,generateRouterProps
FN:59,(anonymous_1)
FN:65,(anonymous_2)
FN:71,(anonymous_3)
FN:81,(anonymous_4)
FN:91,(anonymous_5)
FN:105,(anonymous_6)
FN:116,(anonymous_7)
FN:127,(anonymous_8)
FN:137,(anonymous_9)
FN:149,(anonymous_10)
FN:158,(anonymous_11)
FN:169,(anonymous_12)
FN:180,(anonymous_13)
FN:195,(anonymous_14)
FN:222,(anonymous_15)
FN:231,(anonymous_16)
FN:258,(anonymous_17)
FN:264,(anonymous_18)
FN:277,(anonymous_19)
FN:287,(anonymous_20)
FN:307,(anonymous_21)
FN:319,(anonymous_22)
FN:331,(anonymous_23)
FN:342,(anonymous_24)
FN:354,(anonymous_25)
FNF:26
FNH:23
FNDA:22,generateRouterProps
FNDA:18,(anonymous_1)
FNDA:6,(anonymous_2)
FNDA:14,(anonymous_3)
FNDA:7,(anonymous_4)
FNDA:0,(anonymous_5)
FNDA:2,(anonymous_6)
FNDA:0,(anonymous_7)
FNDA:7,(anonymous_8)
FNDA:1,(anonymous_9)
FNDA:1,(anonymous_10)
FNDA:1,(anonymous_11)
FNDA:1,(anonymous_12)
FNDA:1,(anonymous_13)
FNDA:22,(anonymous_14)
FNDA:4,(anonymous_15)
FNDA:4,(anonymous_16)
FNDA:40,(anonymous_17)
FNDA:18,(anonymous_18)
FNDA:0,(anonymous_19)
FNDA:14,(anonymous_20)
FNDA:8,(anonymous_21)
FNDA:10,(anonymous_22)
FNDA:4,(anonymous_23)
FNDA:12,(anonymous_24)
FNDA:4,(anonymous_25)
DA:57,22
DA:60,18
DA:61,18
DA:66,6
DA:67,6
DA:72,14
DA:73,14
DA:82,7
DA:85,7
DA:92,0
DA:95,0
DA:106,2
DA:109,2
DA:117,0
DA:120,0
DA:128,7
DA:131,7
DA:138,1
DA:141,1
DA:150,1
DA:151,1
DA:159,1
DA:162,1
DA:170,1
DA:173,1
DA:181,1
DA:184,1
DA:195,4
DA:203,22
DA:204,22
DA:222,4
DA:235,4
DA:258,40
DA:265,18
DA:278,0
DA:291,14
DA:308,8
DA:320,10
DA:332,4
DA:343,12
DA:355,4
LF:41
LH:36
BRDA:198,0,0,22
BRDA:236,1,0,4
BRDA:236,1,1,2
BRDA:292,2,0,14
BRDA:292,2,1,2
BRF:5
BRH:5
end_of_record

This is my sonar-project.properties file:

sonar.projectKey=XXX
sonar.organization=XXX

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=XXX
sonar.projectVersion=0.1
sonar.verbose=true

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=./src,./e2e
sonar.exclusions=**/*.snap

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

sonar.javascript.lcov.reportPaths=**/lcov.info
sonar.coverage.exclusions=**/*.test.ts,**/*.test.tsx,**/*.spec.ts,src/tests/**
sonar.cpd.exclusions=**/*.test.ts,**/*.test.tsx,**/*.spec.ts

Any support or advice would be much appreciated! Even advice on how I can better diagnose the issue would be greatly appreciated - turning on verbose didn’t expose any helpful errors.

My issue ended up being that my unit test coverage report was being generated by v8, while my e2e test report was generated by Istanbul. Once I had instanbul generate my unit test report too, coverage was being reported correctly.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.