feat(jest-transform): support transformers written in ESM#11163
feat(jest-transform): support transformers written in ESM#11163SimenB merged 10 commits intojestjs:masterfrom
Conversation
| }; | ||
|
|
||
| module.exports = async function createRuntime(filename, config) { | ||
| const {default: NodeEnvironment} = await import('jest-environment-node'); |
There was a problem hiding this comment.
import in tests doesn't work anymore since I removed the babel plugin
| let transformer: Transformer; | ||
|
|
||
| try { | ||
| transformer = require(transformPath); |
There was a problem hiding this comment.
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.
|
|
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. |
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