jest-preset-angular: [Bug]: 12.2.2 breaks branch coverage
Version
12.2.2
Steps to reproduce
- Create a sample class with decorator like this
import { Pipe, PipeTransform } from '@angular/core'; import { ConfigService } from './config.service'; @Pipe({ name: 'config', }) export class ConfigPipe implements PipeTransform { constructor(private service: ConfigService) {} - Execute and wondering why there are four branches.
Expected behavior
Expect that there are still zero branches.
Actual behavior
Four branches are counted.

Additional context
No response
Environment
System:
OS: Windows 10 10.0.19043
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 16.14.2 - C:\nodejs\node.EXE
npm: 8.5.0 - C:\nodejs\npm.CMD
npmPackages:
jest: ~28.1.0 => 28.1.3
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (5 by maintainers)
I can confirm the issue is related to the forgotten
emitDecoratorMetadatain our case. Fun fact the angular migration does not remove it automatically from the existing tsconfig.json files.Angular 12 removed the need of
emitDecoratorMetadataso I think that was why the example app doesn’t have it. That option in general shouldn’t be needed anymore.FYI with that option true, the emitted codes will be like in this example https://www.typescriptlang.org/tsconfig#emitDecoratorMetadata, and notice that
design:paramtypesis in emitted codes. Thisdesign:paramtypeswas replaced in the workaround mentioned in https://github.com/istanbuljs/istanbuljs/issues/70#issuecomment-975654329I think it’s more on Istanbul side to solve it completely. The solution which alters the compiled output looks to me like a workaround rather than a right way. I think we should push Istanbul to fix it.
In the meantime, maybe using v8 coverage is better?
Oh man, I just hit this today, upgrading Angular from 14.1.0 to 14.2.2. Glad it’s not just me. That issue in istanbul is like 5 years old though, so it’s curious that a bug that old would rear its head with a minor angular version update. @mandarini did you have success with v8?
It seems that some transitive dependency produces different transformed result. There is nice work and writeup by @mandarini on https://github.com/mandarini/isolatedm-jest
Would it be possible to consider incorporating work above into
jest-preset-angular(maybe under additional option)? It would simplify patching huge workspaces with many projects.