fix: repair caching of typescript compiler instances #13099
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
After updating to jest 28, testing crashes when loading multiple TypeScript jest config files (e.g.
jest --projects jest-node.config.ts jest-jsdom.config.ts
). This only appears to happen, if the files import something. The issue has been documented previously in kulshekhar/ts-jest#3691.The cause was a race condition when creating the typescript compiler service, leading to ts-node being registered multiple times. This causes a crash similar to TypeStrong/ts-node#883.
Test plan
I added integration tests based on the multiProjectRunner test. They verify that:
The first and the second test would have already passed previously, the third failed previously.