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

fix: exclude dynamic import plugin from babel config #150

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Sep 14, 2022

#148 (comment)

Diff in built files:

diff --git i/build/createJestRunner.js w/build/createJestRunner.js
index f285e8e..2286138 100644
--- i/build/createJestRunner.js
+++ w/build/createJestRunner.js
@@ -7,8 +7,6 @@ exports.default = createRunner;
 var _jestWorker = require("jest-worker");
 var _pLimit = _interopRequireDefault(require("p-limit"));
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
-function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
 function determineSlowTestResult(test, result) {
   // See: https://github.com/facebook/jest/blob/acd7c83c8365140f4ecf44a456ff7366ffa31fa2/packages/jest-runner/src/runTest.ts#L287
   if (result.perfStats.runtime / 1000 > test.context.config.slowTestThreshold) {
@@ -40,7 +38,7 @@ function createRunner(runPath, {
       return options.serial ? this._createInBandTestRun(tests, watcher, onStart, onResult, onFailure, options) : this._createParallelTestRun(tests, watcher, onStart, onResult, onFailure, options);
     }
     async _createInBandTestRun(tests, watcher, onStart, onResult, onFailure, options) {
-      const runner = (await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(runPath.toString())).default;
+      const runner = (await import(runPath.toString())).default;
       const mutex = (0, _pLimit.default)(1);
       return tests.reduce((promise, test) => mutex(() => promise.then(() => {
         if (watcher.isInterrupted()) {

@mrazauskas
Copy link
Contributor

Another though. If we have const runner = (await import(runPath)).default, is the following still needed:

if (typeof runner.default === 'function') {
return runner.default(baseOptions);
}

@SimenB
Copy link
Member Author

SimenB commented Sep 14, 2022

Good catch 👍

lib/createJestRunner.ts Outdated Show resolved Hide resolved
@SimenB
Copy link
Member Author

SimenB commented Sep 14, 2022

I'm wondering if we should wait with this. now it's require just like before. With import ESM is supported, but I don't think jest-worker supports ESM? As long as it doesn't it's sorta weird that it works in band in this module, but not with workers

@mrazauskas
Copy link
Contributor

Makes sense. Probably this should wait for ESM support in jest-worker.

@SimenB SimenB marked this pull request as draft September 14, 2022 11:01
@SimenB SimenB force-pushed the exclude-dynamic-import-plugin branch from c7a6cc2 to 324b85f Compare September 14, 2022 11:03
@SimenB SimenB force-pushed the exclude-dynamic-import-plugin branch from 324b85f to bb3da7e Compare March 6, 2023 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants