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