ts-jest
ts-jest copied to clipboard
With cached results, changes to type definitions are not detected between packages
🐛 Bug Report
When a typescript package is compiled with type info, changes to the type info may be missed by ts-jest when the package is referenced from another package. Similar to #1747 but not identical.
To Reproduce
Steps to reproduce the behavior: Unzip the attached zip file and follow the README.txt, which is copied inline here:
In the examplePackage folder, run: yarn yarn build yarn link
In the consumerWithTest folder, run: yarn yarn link @example/package yarn test
So far so good (the jestCache folder is created).
Now edit index.ts to uncomment b: number;
and in the examplePackage folder, run:
yarn build
In the consumerWithTest folder, run: yarn test
This should fail due to the change in type definition in index.ts, but passes. Running yarn test --no-cache correctly identifies the problem.
Expected behavior
Type info should be respected without clearing the cache
Link to repo (highly encouraged)
Debug log:
# content of ts-jest.log :
envinfo
System:
OS: Windows 10
Node version: v14.16.1
Npm packages:
jest: (included in zip) 27.0.6
ts-jest: (included in zip) 27.0.3
typescript: (included in zip) 4.3.4
Hi @ahnpnl. Other than the mention in #2696, I haven't seen any official acknowledgement of this bug. The other bug mentioned a design choice. Does that mean a significant redesign is in the works?
I would say yes, it’s quite a change, generally speaking is: moving type check to one phase earlier in transform process.
The current design is: collecting all dependencies to construct cache keys and let Jest handle when a file needs to be rechecked.
What I have in mind for a design change is: instead of letting Jest handle, we would always do type check before creating a Jest cache key (ofc only do this when user uses cache). Following this approach will technically solve issues but probably require a smart way of caching for ts-jest
so that we only do type check for files which have been changed or when its dependencies have been changed.
Is there any ETA on when this bug might be fixed? Our team keeps experiencing it and it's quite costly for us.
For the record, I ended up working around this. I changed our build scripts to compile our test code with the TS compiler, not just the product code. We still use ts-jest to run the tests but the cache bug won't affect us because compilation errors are caught by the TS compiler.