feat(jest-transform): support transformers written in ESM #11163
Conversation
| @@ -46,9 +49,6 @@ const setupTransform = (config, rootDir) => { | |||
| }; | |||
|
|
|||
| module.exports = async function createRuntime(filename, config) { | |||
| const {default: NodeEnvironment} = await import('jest-environment-node'); | |||
SimenB
Mar 6, 2021
Author
Collaborator
import in tests doesn't work anymore since I removed the babel plugin
import in tests doesn't work anymore since I removed the babel plugin
| let transformer: Transformer; | ||
|
|
||
| try { | ||
| transformer = require(transformPath); |
SimenB
Mar 7, 2021
Author
Collaborator
we might consider adding a Map to the module scope for the require and import calls. However, they should be by reference when called multiple times in the same context, so I don't think the overhead is necessarily worth it?
we might consider adding a Map to the module scope for the require and import calls. However, they should be by reference when called multiple times in the same context, so I don't think the overhead is necessarily worth it?
Codecov Report
@@ Coverage Diff @@
## master #11163 +/- ##
==========================================
- Coverage 64.20% 64.14% -0.06%
==========================================
Files 307 307
Lines 13364 13373 +9
Branches 3257 3259 +2
==========================================
- Hits 8580 8578 -2
- Misses 4080 4089 +9
- Partials 704 706 +2
Continue to review full report at Codecov.
|
ab014c1
into
facebook:master
|
yeyyyyyyyyyyyy |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Summary
This allows people to write their transformers in ESM. This is mostly a refactor since
import()is async, I've changedScriptTransformerto load all transformers when it's created rather than on demand.To not force all consumers to call
load, I now expose more of a factory method which does the extra function call for the user.This solves the use case behind #11081, but I think that issue might be useful for other async work.
I'll need to update docs here, but I'll do that after landing docusaurus 2Just added a line, I think since we don't mess with versioned docs it should be fineTest plan
E2E test added