nx: V13 upgrade : Jest has detected the following 2 open handles potentially keeping Jest from exiting
Hi I am getting the following error on JEST test execution after the angular v13 upgrade,
`Jest has detected the following 2 open handles potentially keeping Jest from exiting:
● MESSAGEPORT
> 1 | import 'jest-preset-angular/setup-jest';
| ^
2 |
at startWorkerThreadService (../../../../node_modules/jest-preset-angular/node_modules/esbuild/lib/main.js:1978:48)
at ScriptTransformer.transformSource (../../../../node_modules/@jest/transform/build/ScriptTransformer.js:612:31)
at ScriptTransformer._transformAndBuildScript (../../../../node_modules/@jest/transform/build/ScriptTransformer.js:758:40)
at ScriptTransformer.transform (../../../../node_modules/@jest/transform/build/ScriptTransformer.js:815:19)
at Object.<anonymous> (../../../../node_modules/jest-preset-angular/setup-jest.js:1:100)
at Object.<anonymous> (src/test-setup.ts:1:1)
`
Can someone please help to fix this issue?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 37
- Comments: 27 (6 by maintainers)
Hi there
We have the same issue in our project and i first openend https://github.com/thymikee/jest-preset-angular/issues/1426 with a reproducible example but it looks more like a problem with angular itself and jest-preset-angular is only an indirection and thats why we opened https://github.com/angular/angular/issues/45776.
Lets see if they have some insights.
Same here. The issue as far I can see is related to Jest and not angular nor jest-preset-angular. https://github.com/angular/angular/issues/45776#issuecomment-1143552218
I’ve managed to “fix” this issue by changing
transformIgnorePatterns: ['node_modules/(?!.*.mjs$)']totransformIgnorePatterns: ['/node_modules/?!@angular'], “angular” being my problematic import in this case. I’ve also removed all the newly added lines withteardown: { destroyAfterEach: false }My resolution (and root cause of the problem in my CI) is very environment specific, so it’s definitely not going to be a general fix, but it might help one or two people who are running in containerized build environments and oversubscribing their memory allocation.
In docs of jest-preset-angular https://thymikee.github.io/jest-preset-angular/docs/guides/angular-13+/ they write: Before upgrading to ng13 and switching to ES Modules, your
setup-jest.tsfile most likely uses thepreset setup-jest, like the following:The
jest-preset-angular/setup-jestfile doesn’t work with ESM, because it usesrequire. For now you should skip using this file, and replace the contents of yoursetup-jest.tswith:It works for me, but increase test time.