Coverage lines reference different file


  • Scanner configuration file: /usr/local/Cellar/sonar-scanner/
  • Project root configuration file: /Users/-----/Documents/Projects/base-environment/
  • SonarScanner
  • Java 11.0.12 Homebrew (64-bit)
  • Mac OS X 12.2.1 x86_64
  • Jest: “^27.5.1”
  • jest-sonar-reporter: “^2.0.0”
  • Node: 16.14.0
  • NPM: 8.3.1


The project is a docker image, nested within there’s 2 node projects that have similar structure, Jest is run in each node project to generate coverage, and SonarScanner is run to collect & upload the coverage to SonarQube as a test before automating it inside the CI/CD, to illustrate the 2 files I have an issue as well as the folder structure, please look at the image.
Screen Shot 2022-03-03 at 4.49.05 PM


These 2 files not only share a similar path except the name of the root of each project (gateway or renderer), but also repeat some code as well (a little bit, but differences are noticeable right when you open), however the coverage that has been run is the one for gateway project, but the coverage lines report the result inside renderer which of course makes no sense.


Could you share your analysis logs?


Found something, since Jest creates an using the module’s folder as root (basically each path starts from /src) when SonarScanner goes through it doesn’t know which config.ts it refers to so I guess it grabs the first it can find, I can confirm this as modifying this path before running the scan fixes the issue.

My team and I had to add some custom preprocessing scripts to our CI/CD to sed the path and prefix-it with the expected path (the relative path from the root of the repo, not the src folder).

It would be nice if SonarScanner could take into account the path from the to the file when scanning so this doesn’t become a recurrent issue we have to fix in every project’s CI/CD.

1 Like


I’m so glad you figured this out!

I’ll raise this internally.


1 Like

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