Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Jest cache busting for ts/tsx files #79

Merged
merged 1 commit into from
Jun 23, 2017

Conversation

zinserjan
Copy link
Contributor

I noticed some caching issues with Jest cause changes to my tsconfig.json wasn't recognized.

Jest caches transformed module files to speed up test execution. If you are using your own custom transformer, consider adding a getCacheKey function to it
https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues

This PR adds a cache-key function which generates the key based on:

  • the content of the transformer (to be ready for changes in the future)
  • the content of the file to transform
  • the jest config
  • the ts compiler config
  • the code-coverage flag

Based on https://github.com/facebook/jest/blob/b254715310d800330479aad6996b4bc0716feaa2/packages/babel-jest/src/index.js#L80

@wmonk wmonk merged commit 0b2821f into wmonk:master Jun 23, 2017
@AJamesPhillips
Copy link
Contributor

AJamesPhillips commented Jun 27, 2017

@zinserjan I haven't tried this out yet but if you want to bust the cache of the tsconfig file itself you need to read it every time typescriptTransform.js is run. Currently it (appears) to be required once and never refreshed? 0618b12#diff-2906b56aa1e1e3c1e5268fc886c168cfR18 Have I misinterpreted this? Does changing the tsconfig.json options cause the cache to be bust for you?

@zinserjan
Copy link
Contributor Author

@AJamesPhillips we use the compilerOptions part of the tsconfig for compiling & hashing. So yes, changes to compilerOptions affects the cache busting.

@AJamesPhillips
Copy link
Contributor

AJamesPhillips commented Jun 27, 2017

But you've "required" it only once via the const tsconfig = tsc.readConfigFile(tsconfigPath).config; line, and assigned it to the variable compilerConfig with: compilerConfig = tsconfig.compilerOptions;. Once the file contents change, running the exported getCacheKey function will not see a changed compilerConfig variable but the existing variable no? Surely it won't bust the cache?

@zinserjan
Copy link
Contributor Author

Once the file contents change, running the exported getCacheKey function will not see a changed compilerConfig variable but the existing variable no? Surely it won't bust the cache?

Yep you have to restart jest to bust the cache. That shouldn't be a problem cause it's the same behaviour like with ts-loader.

But automatic invalidation of processed ts files for jest and webpack without restarting would be a cool feature.

I see two tasks to do this:

  • let ts-loader also watch the tsconfig.json (Watch tsconfig.json TypeStrong/ts-loader#55) so webpack would invalidate automatically
  • investigate how we can invalidate and restart all affected files/tests in jest when tsconfig.json changes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants