-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "dependencies" in jest transformers #6680
Comments
Does #7313 (and #7349, #7350) cover this use case? It allows you to tell It'll be available in the next major of Jest (currently at |
Yes, it sounds like it solves that. Thanks @SimenB 😸 cc @yanivefraim |
Awesome! Closing then 🙂 Happy to reopen if it isn't enough. Docs: https://jestjs.io/docs/en/next/configuration#dependencyextractor-string |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey! 👋
Thanks for all the hard work you're putting in Jest. I love it. So thanks ❤️
I'm not quite sure that what I'm asking for is right, but I hope so - I haven't thought about a different way to solve my problem.
🚀 Feature Proposal
Adding a way to declare code dependencies in jest transform steps, that will eventually help jest to know when to invalidate cache (for babel compilation, etc)
Motivation
Imagine that you use prepack for some of your code and you want to test it. You'd probably write a babel plugin (or a custom transformer) to do that. Unfortunately,
prepack
, like any other "bundler" with runtime, will leverage dependencies. This means, that the cache that jest has on the file (which is basically its file name) isn't good enough.It's not just for "prepack" or bundlers, if we'll take a look at @kentcdodds's
import-all.macro
, we'll see that you can import a directory usingimportAll('./dir/*.js')
. If we can say "this code depends on any file in this directory".Even when declaring
getCacheKey
, for some reason the cache doesn't invalidate while inwatch
mode.Currently, if you use some kind of "bundler" or any babel plugin/macro like this, you need to use
--no-cache
in jest.Example
Currently, a custom jest transformer can compile files using custom steps:
I'm suggesting adding a method or data structure that will provide a way to include the dependencies:
This way jest will know when to invalidate the cache (whenever one of these files changes!)
we can still support the
string
return value fromprocess
for simpler usages!Pitch
Supporting explicit dependencies will help making our apps more testable. Changes in
sass
files could be watched in Jest. Prepack, webpack configurations, etc, will be able to be tested too. Wider babel plugins support.Actually, what I'd like more is a way of sharing these dependencies between babel plugins and jest without writing a custom transformer. but maybe that'll be a PR for
babel-jest
after landing this feature! 😸The text was updated successfully, but these errors were encountered: