Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch coverage is wrong for angular projects with Jest #818

Closed
danil-z opened this issue Oct 17, 2018 · 14 comments
Closed

Branch coverage is wrong for angular projects with Jest #818

danil-z opened this issue Oct 17, 2018 · 14 comments

Comments

@danil-z
Copy link

danil-z commented Oct 17, 2018

Issue :

Branch coverage is wrong , seems ts-jest transpiles injectables with some sort of branching and differs from tsc

related issues:

Expected behavior :

100% coverage

Minimal repo :

Following repo generated with angular cli, added 1 simple button with router action and test for it.
It reports uncovered branch in constructor with injectable Router service.

https://github.com/danil-z/covjest

@huafu
Copy link
Collaborator

huafu commented Oct 17, 2018

@danil-z coverage are wrong due to outdated angular preset. I have since a long time some WIP on the angular preset to make it compatible with latest version of ts-jest, but I had to leave it by side as I'm really busy on other projects.

Anyway, it's ok to keep this issue open for others to know, but issue is actually angular preset that needs to be updated to make it compatible with ts-jest >= 23.10. There might already be an issue there tho.

@danil-z
Copy link
Author

danil-z commented Oct 17, 2018

If you could explain it little bit more, or what exactly is required I'd submit them PR

@danil-z
Copy link
Author

danil-z commented Oct 17, 2018

I've tried to update dependency on ts-jest

"jest-preset-angular": "ahnpnl/jest-preset-angular#dependabot/npm_and_yarn/ts-jest-23.10.4",

but still experiencing same coverage bug

@danil-z
Copy link
Author

danil-z commented Oct 17, 2018

here is open ticket about supporting ts-jest >= 23.10 in angular preset
thymikee/jest-preset-angular#195

@huafu
Copy link
Collaborator

huafu commented Oct 18, 2018

@danil-z FYI I've posted there little explain and link to WIP PR with my local work so far

@itslenny
Copy link

@danil-z

FYI - There has been an issue about this on istanbul for almost 2 years. There is also a matching issue on jest, and jasmine, and everything else that depends on it. So, it's not very likely this will be resolved any time soon. Seeing my 50% branch coverage makes me cry myself to sleep at night. Welcome to the party. :-(

@ahnpnl
Copy link
Collaborator

ahnpnl commented Dec 5, 2018

fixed in ts-jest >= 23.10.x or jest-preset-angular 7.0.0-alpha.1 (for people who uses jest with Angular)

@Rush
Copy link

Rush commented Oct 22, 2019

@ahnpnl Do you know what was the exact fix? I am asking because I am still seeing the issue with coverage for dependency injection.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Oct 22, 2019

Hi, the fix in ts-jest starting from 23.10 that ts-jest uses AST transformer + TS compiler internally via isolatedModules config option to fix that coverage issue.

@Rush
Copy link

Rush commented Oct 22, 2019

Got it. I've been using this flag actually. Maybe my problem is something different but I'm still seeing the issue:
image

I have:

    globals: {
        'ts-jest': {
            tsConfig: '<rootDir>/test/unit/tsconfig.json',
            ignoreCoverageForDecorators: true,
            ignoreCoverageForAllDecorators: true,
            stringifyContentPathRegex: '\\.html$',
            astTransformers: [
                'jest-preset-angular/build/InlineFilesTransformer',
                'jest-preset-angular/build/StripStylesTransformer'
            ],
            isolatedModules: true,
        },
    },
    preset: 'jest-preset-angular',
  • ts-jest@24.1.0
  • jest-preset-angular@8.0.0

@ahnpnl
Copy link
Collaborator

ahnpnl commented Oct 22, 2019

Last time I checked the coverage is correct if leaving isolatedModules with false value (default), true value will make the issue appear again.
There is a performance cost to leave it with false value but you will get type checking + coverage issue gone.

@Rush
Copy link

Rush commented Oct 22, 2019

@ahnpnl indeed, setting isolatedModules: false fixes coverage (tested running a single spec file) but the downside is the tests are loading forever (almost 10 minutes now) before even running the first suite.

Test Suites: 0 of 302 total
Tests:       0 total
Snapshots:   0 total
Time:        534s

And still counting ...

Is there a chance to make coverage work properly with isolatedModules: true. Also why is it taking that long?

If I do tsc --noEmit -p test/unit/tsconfig.json it runs very fast and I get type checking outside jest.

@de-don
Copy link

de-don commented Mar 15, 2024

Still actual issue :(

@douglasjunior
Copy link

douglasjunior commented Jun 7, 2024

Same here when using isolatedModules: true:

image

Unfortunately isolatedModules is the only thing that help us with the slow test run in monorepos jestjs/jest#10833

😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants