-
-
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
Support ESM versions of all pluggable modules #11167
Comments
I think it’s wise to pin this issue so it stands out to everyone :) |
sure 🙂 |
I think we can already drop the support node 10 for |
D-Day for Node 10 is here xD |
Jest 27 will support Node 10 so people who are stuck on older versions (of which there are many) can use it |
@SimenB you listed |
|
Maybe that's one of the modules I am using but I cannot use ESM in my |
Could you open up a new issue with a reproduction? |
Should |
Hmm, maybe. I'd have assumed that worked as it should seeing as it should just remap the identifier and the rest should work as "normal". Is that not the case? |
I tested it, and it does work 😆 |
Hi @SimenB,
After I dived into it, I found there're some problems that I can't solve by myself. dependencyExtractor
So the only chance I could find is to make the whole HasteMap factory async like this: await HasteMap.create(...); Is this a right approach? prettierPath
This I currently don't have enough knowledge about how to handle this with ESModules. snapshotResolver & snapshotSerializersThose two are relying on the So, should we pass |
Wonderful, thanks!
Yeah, that seems correct. Makes it a breaking change though, so need to wait for Jest 28.
Good point, we might have to leave that alone. This is for a specific module (
Yeah, passing in |
Passing How about replacing |
That should work as well 👍 |
@SimenB is there any work left to do? I am very glad to push these things forward. |
Great! The ones not crossed out in the OP are still missing. Not sure how feasible they are |
@SimenB is this waiting for nodejs team to provide support? |
HI @SimenB |
Is it possible to make |
Prettier seems to have moved on to ESM: https://prettier.io/blog/2023/07/05/3.0.0.html. |
🎻 |
Once Node 10 is EOL at the end of April, lots of libraries and modules will probably be written in native ESM rather than CJS. While we've mostly been focusing on getting tests running in ESM, we're sorta limited/slowed down by the fact the
vm
APIs are experimental and flagged on Node's side. That is not the case for "normal" ESM.We already support user configuration written in ESM.
With that in mind, all modules in Jest that are "pluggable" should be able to load ESM.
dependencyExtractor
(feat(jest-haste-map): supportdependencyExtractor
written in ESM #12008)globalSetup
(feat(jest-core): add support forglobalSetup
andglobalTeardown
written in ESM #11267)globalTeardown
(feat(jest-core): add support forglobalSetup
andglobalTeardown
written in ESM #11267)preset
(feat(jest-config): add support forpreset
written in ESM #11200)prettierPath
reporters
(feat: support reporters written in ESM #11427)resolver
runner
(feat: requireAndTranspileModule support ESM #11232)snapshotResolver
snapshotSerializers
testEnvironment
(feature: allow ESM for test environment #11033)testResultsProcessor
(feat(jest-core): supporttestResultsProcessor
written in ESM #12006)testRunner
(feat: requireAndTranspileModule support ESM #11232)testSequencer
(feat(jest-core): Add support for testSequencer written in ESM #11207)transformers
(feat(jest-transform): support transformers written in ESM #11163)watchPlugins
(feat(jest-core): add support forwatchPlugins
written in ESM #11315)Any and all help here would be greatly appreciated!
In general, it means attempting to
require
, and if that fails with an ESM error, useimport()
and verify it's thedefault
export. Paired with an integration test that has the module in question written in ESM and verifying it works.Example: https://github.com/facebook/jest/blob/ab014c140af2e10ae7c5790c2406009790787cdb/packages/jest-transform/src/ScriptTransformer.ts#L177-L196
Whenever we drop Node 10 (probably for Jest 28) we can do just the
import
call as that can load both ESM and CJS, but that'll be a simple refactor as it's just removing the initialrequire
andtry-catch
. So I still think it's worth it to add support now as the code difference is quite small and the later refactor is minimalThe text was updated successfully, but these errors were encountered: