-
-
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
Implement async code transformations #9504
Comments
@SimenB I was looking into |
Ah, to load Babel's config? That makes sense. |
Does this affect to current custom transformers’ implementation ? I’m curious about the performance can be gained with async |
|
@ahnpnl not unless they want to, it'll be opt-in. If the transformer doesn't export async functions, we'll fallback to the synchronous ones. @the-spyke good point! I'm starting to wonder if we should export both |
I did some experiment yesterday with |
I am interested in this, can I help? |
Yes please! It's somewhat invasive, but I'll be happy to work on it with you. I haven't figured out if it makes the most sense to add Regardless, these functions should then call Let's start with just adding support to |
Thank you, @SimenB! Just so I understand it correctly: We want to enable transformation itself to be async, that means when client calls No matter we are going |
yup, that summary sounds correct.
I'm not sure if we should force transformers to work in sync mode - there might be cases where a transformer won't work synchronously, and we shouldn't ban that use case. So I'm thinking 2 separate interfaces, one with optional |
maybe my question here won't be related to this feature but is it possible to have a post process hook in |
Do you mean something like the following?
And
|
There is no point at which "all files have been transformed" as there might be
Yup! |
Is there a way for transformer to access some sort of “after test run finish” hook ? I know there are some hooks which are available for watch plugin but transformer doesn’t have. |
Not really at the moment. You could implement it as a reporter, but I'm guessing you want to access some state or some such... Transformers can run in different workers though, so even that might not work. Regardless, not really related to this issue. Could you open up a new one, and describe your use case for it? |
(Partially off topic) I'm exploring shipping Babel as native ESM, and this means that it would be impossible to synchronously do Does Jest have a mechanism to pre-load things before compiling ( |
That would break current transformers indeed. We can add some sort of "preload" to transformers where they can do whatever they want async so that they're ready to transform code synchronously (e.g. do Can you open up a new issue with that feature request? SOrta orthogonal to async transformation |
I like the idea of having "preload" phase for transformers. That will solve quite some problems with performance for Currently I am experimenting a workaround is
so in this workaround, I can pass |
Let's discuss this in a separate issue 🙂 |
Gave this some more though when working on #11150 (leaving in an extra |
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. |
EcmaScript Modules can (actually must, but easy to wrap the sync stuff in a promise) resolve asynchronously. While it's in no way a blocker for ESM support in Jest, it would be nice to add support for async transforms to be used.
This logic should for now not impact anything in Jest beyond
@jest/transform
as Jest wouldn't use it until ESM support is in place.I'm thinking we can add a
.transformAsync
and.transformSourceAsync
to theScriptTransformer
class.There are some checks and verifications that
process
is a function - we need to make sure there is one clear code path for sync and one for async transformation that verify the provided reporter implements the correct interface.Sort of reopening #5556 and all its linked issues.
The text was updated successfully, but these errors were encountered: