When you make changes to the types, e.g. renaming a type, the changes cause the test to fail, even if the change actually works fine.
Need to quit jest watch and start again for the changes to be picked up correctly.
My guess is that during rename, multiple files are affected and ts-jest only detect one file has been changed, so the cache of other files are not invalidated, thus containing outdated information.
This happens whenever I make changes to multiple files and save them at the same time.
Another example would be moving a type from one file to another.
I encounter this in multiple situations. For example, https://github.com/unional/progress-str
To reproduce the issue, you need to run the test in watch mode (npm run watch in the repo above),
and then make some changes such as rename or move types.
Note that this does not occur every time, but I encounter this about 3-4 times a day.
If I encounter again, I'll post more detail about how to reproduce this.
Seeing this issue as well. It's really frustrating. I can even clear out a whole file that has types and it isn't picked up.
I stumble upon of similar issue. And I guess I have an explanation of what's going on.
As you may know TS type information only exists during development and removed upon compilation. Jest compiles files one by one and stores result in cache.
Now consider following example:
File1: type definitions
File2: imports File1
Run tests. All is OK. Jest will cache compiled File1 and File2.
Scenario 1:
Change File1 and break type (rename, change signature, etc.). What will happen?
File2: still the same, cached version is used. Therefore tests aregreen.
Scenario 2:
Now change File1 and File2. Save them both together.
File2: new, Jest will compile it.
File1: new, Jest will compile it. TS will pickup breaking change reporting anerror.
Workaround: use --no-cache when running tests.
I am running into this problem also. Any updates?
hi @unional @aaw5017 @antonovicha @nathanmarks would you please help us to test the fix ? You can download tgz file here and install it. Remember to clear cache before you run your tests
Hi @ahnpnl , my current projects do no do type checks through jest anymore, because it slow me down unnecessary.
So my projects are not using ts-jest now. Since this will likely require bigger project to reproduce, I won't be able to help testing the fix at the moment. Thanks. 🌷
I also experienced this, I made a minimal repository with steps to reproduce:
https://github.com/kevinsimper/jest-ts-jest-import-error
Steps to reproduce:
$ npm test -- --watchsrc/add.test.ts and edit the import from add1 to add2 in both import and where the function is used FAIL src/add.test.ts
● Test suite failed to run
src/add.test.ts:1:10 - error TS2305: Module '"./add"' has no exported member 'add2'.
1 import { add2 } from "./add";
./add and fix the function to be called add2.I have been frustrated by this too. Would love to know if you find a solution.
At least I now know it is not a problem with my environment.
omg i just had this problem, arrives here after googling, saw you fixed it 5 hours ago: awesome! :tada:
Nice, which version will contain this fix and when can you release it?
v27 :) currently working on support jest 27 too. So when jest 27 is out, ts-jest will follow
Most helpful comment
I stumble upon of similar issue. And I guess I have an explanation of what's going on.
As you may know TS type information only exists during development and removed upon compilation. Jest compiles files one by one and stores result in cache.
Now consider following example:
Run tests. All is OK. Jest will cache compiled File1 and File2.
Scenario 1:
Scenario 2:
Workaround: use --no-cache when running tests.