Open spalger opened 1 year ago
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Still an issue in jest 29.7.0: https://github.com/spalger/reproduce-issues/commit/33880e7f2a39e64608118654bef19f8297318039
Seeing this too
Not sure how to handle this. There is no readInitialCoverage
equivalent for v8 coverage. Also, it'd make a coverage run be slower as we'd need to transform the file.
I think the easiest is to just add type only files to coveragePathIgnorePatterns
config
Version
29.5.0
Steps to reproduce
Repro code is in a branch on my reproduce-issues repo: https://github.com/spalger/reproduce-issues/tree/jest/v8-coverage-untested-ts-files
clone repro branch:
Install packages and run tests
Expected behavior
types.ts
only includes a single interface, so the file should should be ignored for the purpose of coverage calculation.Actual behavior
types.ts
is not imported during test execution because TypeScript strips type-only imports by defaulttypes.ts
is reported as missing coverage on lines 1-3Additional context
This only happens when using the v8 coverage collection because of this condition: https://github.com/jestjs/jest/blob/main/packages/jest-reporters/src/CoverageReporter.ts#L188-L190
A workaround is available: set the
"importsNotUsedAsValues": "preserve"
compiler option when setting upts-jest
ensuring that all types referenced in the code base will be imported during tests.Environment