Description
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, use import()
and verify it's the default
export. Paired with an integration test that has the module in question written in ESM and verifying it works.
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 initial require
and try-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 minimal