Ts-jest: type changes not updated during watch mode

Created on 10 Jan 2019  ·  12Comments  ·  Source: kulshekhar/ts-jest

Issue

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.

causes

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.

Minimal repo

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.

Bug Confirmed Help Wanted

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:

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 are green.

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 an error.

Workaround: use --no-cache when running tests.

All 12 comments

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 are green.

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 an error.

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:

  • run jest with watch $ npm test -- --watch
  • go into src/add.test.ts and edit the import from add1 to add2 in both import and where the function is used
  • see the error:
 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";
  • go into ./add and fix the function to be called add2.
  • see that the jest runner still say the same error
  • restart the runner and see it works now

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vinnl picture Vinnl  ·  3Comments

qm3ster picture qm3ster  ·  3Comments

golddranks picture golddranks  ·  3Comments

jbreckmckye picture jbreckmckye  ·  3Comments

bruk1977 picture bruk1977  ·  3Comments