Skip to content
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

feat(jest-transform): support transformers written in ESM #11163

Merged
merged 10 commits into from Mar 7, 2021

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Mar 6, 2021

Summary

This allows people to write their transformers in ESM. This is mostly a refactor since import() is async, I've changed ScriptTransformer to 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 2 Just added a line, I think since we don't mess with versioned docs it should be fine

Test plan

E2E test added

@@ -46,9 +49,6 @@ const setupTransform = (config, rootDir) => {
};

module.exports = async function createRuntime(filename, config) {
const {default: NodeEnvironment} = await import('jest-environment-node');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import in tests doesn't work anymore since I removed the babel plugin

let transformer: Transformer;

try {
transformer = require(transformPath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-io
Copy link

Codecov Report

Merging #11163 (fc0f616) into master (3c679f1) will decrease coverage by 0.05%.
The diff coverage is 61.36%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
packages/jest-core/src/runGlobalHook.ts 21.73% <0.00%> (ø)
packages/jest-reporters/src/CoverageWorker.ts 33.33% <ø> (ø)
packages/jest-runner/src/runTest.ts 1.98% <0.00%> (ø)
packages/jest-transform/src/ScriptTransformer.ts 63.63% <56.66%> (-2.74%) ⬇️
packages/jest-core/src/TestScheduler.ts 68.18% <87.50%> (ø)
...ckages/jest-reporters/src/generateEmptyCoverage.ts 75.00% <100.00%> (+2.27%) ⬆️
packages/jest-runtime/src/index.ts 55.59% <100.00%> (ø)
packages/expect/src/utils.ts 94.83% <0.00%> (-1.30%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c679f1...fc0f616. Read the comment docs.

@SimenB SimenB merged commit ab014c1 into jestjs:master Mar 7, 2021
@SimenB SimenB deleted the import-transformers branch March 7, 2021 14:38
@ahnpnl
Copy link
Contributor

ahnpnl commented Mar 8, 2021

yeyyyyyyyyyyyy

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants