The Wayback Machine - https://web.archive.org/web/20210806221708/https://github.com/facebook/jest/pull/11163
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
Collaborator

@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');

This comment has been minimized.

@SimenB

SimenB Mar 6, 2021
Author Collaborator

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

let transformer: Transformer;

try {
transformer = require(transformPath);

This comment has been minimized.

@SimenB

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?

@codecov-io
Copy link

@codecov-io codecov-io commented Mar 7, 2021

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 facebook:master Mar 7, 2021
22 of 26 checks passed
22 of 26 checks passed
@github-actions
cleanup-runs
Details
@github-actions
Prepare yarn cache
Details
@github-actions
Running TypeScript compiler & ESLint
Details
@github-actions
Node v10.x on ubuntu-latest
Details
@github-actions
Node v10.x on macOS-latest
Details
@github-actions
Node v10.x on windows-latest
Details
@github-actions
Node v12.x on ubuntu-latest
Details
@github-actions
Node v12.x on macOS-latest
Details
@github-actions
Node v12.x on windows-latest Node v12.x on windows-latest
Details
@github-actions
Node v14.x on ubuntu-latest
Details
@github-actions
Node v14.x on macOS-latest Node v14.x on macOS-latest
Details
@github-actions
Node v14.x on windows-latest
Details
@github-actions
Node v15.x on ubuntu-latest
Details
@github-actions
Node v15.x on macOS-latest
Details
@github-actions
Node v15.x on windows-latest
Details
@github-actions
Node LTS on ubuntu-latest using jest-jasmine2
Details
@github-actions
Node LTS on macOS-latest using jest-jasmine2 Node LTS on macOS-latest using jest-jasmine2
Details
@github-actions
Node LTS on windows-latest using jest-jasmine2
Details
facebook.jest #20210307.17 failed
Details
@facebook-github-tools
Facebook CLA Check Contributor License Agreement is valid!
Details
ci/circleci: test-jest-jasmine Your tests passed on CircleCI!
Details
ci/circleci: test-node-10 Your tests passed on CircleCI!
Details
ci/circleci: test-node-12 Your tests passed on CircleCI!
Details
ci/circleci: test-node-14 Your tests passed on CircleCI!
Details
ci/circleci: test-node-15 Your tests passed on CircleCI!
Details
ci/circleci: test-or-deploy-website Your tests passed on CircleCI!
Details
@SimenB SimenB deleted the SimenB:import-transformers branch Mar 7, 2021
@ahnpnl
Copy link
Contributor

@ahnpnl ahnpnl commented Mar 8, 2021

yeyyyyyyyyyyyy

@github-actions
Copy link

@github-actions github-actions bot commented May 10, 2021

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.
5 participants