TypeScript coverage incorrect

Used GitHub + GitHub Actions (with sonarsource/sonarcloud-github-action@master).

The repository is mainly TypeScript and auxiliary files (like Dockerfile).

Various projects with similar issues, one is SonarCloud.

Given some code like the following:

export class Module {
  id?: number
  name?: string
  isProduct?: boolean
  isErp?: boolean

  constructor(input: Partial<Module>) {
    Object.assign(this, input)
  }
}

When I run Jest locally with --coverage it says 100% coverage, Sonar says only line 8 is covered and gives 25%. What is more absurd is that the function/method content is covered while the method itself not.

image

image

Hi,

Off-hand it’s not clear to me what’s going on here. When you pass a coverage report into analysis, we go by what’s in the report. Is there a comparable screenshot from Jest you can share so I can look at this side-by-side?

 
Thx,
Ann

Hi,

I updated the description with a print of a local run of Jest coverage for this file.

Hi,

To ask a silly question, when you mouseover the red marker, it says ‘Not covered by tests’? And the green one says ‘Fully covered’?

 
Thx,
Ann

Yes, it says the constructor name is not covered while its contents are. The properties are also not covered (they are not callables, how could they?).

image
image

Hi,

Thanks for confirming that. I’ve called for more expert eyes.

 
Ann

Dear @wregis, we are currently looking into your issue and have not been able to reproduce it yet. If you are still encountering the issue, would you mind sharing with us the content of the LCOV file that Jest generates? There may be something there that could help us reproduce and identify the issue.

If you don’t feel like sharing the LCOV file, could you please test it with an LCOV viewer (like https://lcov-viewer.netlify.app/) and compare the results with the coverage report emitted by SonarCloud?