Search code examples
typescriptunit-testingjestjssonarqubecode-coverage

SonarQube coverage deviates of Jest coverage


I'm having hard time to understand why SonarQube has different coverage results compared to Jest coverage.

SQ coverage resultsSQ coverage

Jest coverage ![Jest coverage 3

Jest coverage 4

Jest coverage 1

Jest coverage 2

My question is, why does the coverage deviate with a noticeable amount and how can you prevent this in the future.


Solution

  • If you're talking about, for instance, the values of "82.4%" and "81.25%" (I think that's it, it's too small) for config.provider.ts, that's because SonarQube code coverage is actually a "weighted average" of multiple metrics.

    Look at the details in this thread for the algorithm: https://community.sonarsource.com/t/sonarqube-and-code-coverage/4725