diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts index 51e6621e1347..79da4ab6f3ce 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts @@ -72,10 +72,7 @@ const jestAdapter = async ( }); for (const path of config.setupFilesAfterEnv) { - const esm = runtime.unstable_shouldLoadAsEsm( - path, - config.extensionsToTreatAsEsm, - ); + const esm = runtime.unstable_shouldLoadAsEsm(path); if (esm) { await runtime.unstable_importModule(path); @@ -83,10 +80,7 @@ const jestAdapter = async ( runtime.requireModule(path); } } - const esm = runtime.unstable_shouldLoadAsEsm( - testPath, - config.extensionsToTreatAsEsm, - ); + const esm = runtime.unstable_shouldLoadAsEsm(testPath); if (esm) { await runtime.unstable_importModule(testPath); diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 0ff9f58646f2..7929173509b1 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -151,7 +151,6 @@ export default async function jasmine2( for (const path of config.setupFilesAfterEnv) { const esm = runtime.unstable_shouldLoadAsEsm( path, - config.extensionsToTreatAsEsm, ); if (esm) { @@ -167,7 +166,6 @@ export default async function jasmine2( } const esm = runtime.unstable_shouldLoadAsEsm( testPath, - config.extensionsToTreatAsEsm, ); if (esm) { diff --git a/packages/jest-repl/src/cli/runtime-cli.ts b/packages/jest-repl/src/cli/runtime-cli.ts index dc8557da20cf..1eae32cd1b17 100644 --- a/packages/jest-repl/src/cli/runtime-cli.ts +++ b/packages/jest-repl/src/cli/runtime-cli.ts @@ -99,7 +99,6 @@ export async function run( for (const path of config.setupFiles) { const esm = runtime.unstable_shouldLoadAsEsm( path, - config.extensionsToTreatAsEsm, ); if (esm) { @@ -110,7 +109,6 @@ export async function run( } const esm = runtime.unstable_shouldLoadAsEsm( filePath, - config.extensionsToTreatAsEsm, ); if (esm) { diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 4d1351f3691a..9e92c48e20c6 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -171,7 +171,6 @@ async function runTestInternal( for (const path of config.setupFiles) { const esm = runtime.unstable_shouldLoadAsEsm( path, - config.extensionsToTreatAsEsm, ); if (esm) { diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index 3e371b859671..38dbc9c27df4 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -118,7 +118,6 @@ module.exports = async function createRuntime(filename, config) { for (const path of config.setupFiles) { const esm = runtime.unstable_shouldLoadAsEsm( path, - config.extensionsToTreatAsEsm, ); if (esm) { diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 1ea475c10406..5a03bd290b1a 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -363,7 +363,12 @@ export default class Runtime { } // unstable as it should be replaced by https://github.com/nodejs/modules/issues/393, and we don't want people to use it - unstable_shouldLoadAsEsm = Resolver.unstable_shouldLoadAsEsm; + unstable_shouldLoadAsEsm(path: Config.Path): boolean { + return Resolver.unstable_shouldLoadAsEsm( + path, + this._config.extensionsToTreatAsEsm, + ); + } private async loadEsmModule( modulePath: Config.Path, @@ -499,10 +504,7 @@ export default class Runtime { if ( this._resolver.isCoreModule(resolved) || - this.unstable_shouldLoadAsEsm( - resolved, - this._config.extensionsToTreatAsEsm, - ) + this.unstable_shouldLoadAsEsm(resolved) ) { return this.loadEsmModule(resolved, query, isStaticImport); }