From 80dde6f9d04ec42a0d0ba1a947d391bf5c1faf78 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 28 Apr 2020 11:12:43 +0200 Subject: [PATCH] fix: handle mismatch between circus and runtime versions (#9903) * fix: handle mismatch between circus and runtime versions * changelog --- CHANGELOG.md | 1 + .../jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts | 6 ++++-- packages/jest-jasmine2/src/index.ts | 6 ++++-- packages/jest-runner/src/runTest.ts | 3 ++- packages/jest-runtime/src/cli/index.ts | 6 ++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07c630555d7e..e5d5f1571221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes - `[expect]` Prints the Symbol name into the error message with a custom asymmetric matcher ([#9888](https://github.com/facebook/jest/pull/9888)) +- `[jest-circus, jest-jasmine2]` Support older version of `jest-runtime` ([#9903](https://github.com/facebook/jest/pull/9903) & [#9842](https://github.com/facebook/jest/pull/9842)) - `[@jest/environment]` Make sure not to reference Jest types ([#9875](https://github.com/facebook/jest/pull/9875)) - `[jest-message-util]` Code frame printing should respect `--noStackTrace` flag ([#9866](https://github.com/facebook/jest/pull/9866)) - `[jest-runtime]` Support importing CJS from ESM using `import` statements ([#9850](https://github.com/facebook/jest/pull/9850)) 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 a7fdf68cb0d9..4630f16c56bb 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts @@ -77,7 +77,8 @@ const jestAdapter = async ( }); for (const path of config.setupFilesAfterEnv) { - const esm = runtime.unstable_shouldLoadAsEsm(path); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(path); if (esm) { await runtime.unstable_importModule(path); @@ -86,7 +87,8 @@ const jestAdapter = async ( } } - const esm = runtime.unstable_shouldLoadAsEsm(testPath); + // TODO: remove ? in Jest 26 + 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 03d2eebdc851..c37fe26f7dbc 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -156,7 +156,8 @@ async function jasmine2( }); for (const path of config.setupFilesAfterEnv) { - const esm = runtime.unstable_shouldLoadAsEsm(path); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(path); if (esm) { await runtime.unstable_importModule(path); @@ -177,7 +178,8 @@ async function jasmine2( env.specFilter = (spec: Spec) => testNameRegex.test(spec.getFullName()); } - const esm = runtime.unstable_shouldLoadAsEsm(testPath); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(testPath); if (esm) { await runtime.unstable_importModule(testPath); diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index dd8735be8b57..e57c63539196 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -159,7 +159,8 @@ async function runTestInternal( const start = Date.now(); for (const path of config.setupFiles) { - const esm = runtime.unstable_shouldLoadAsEsm(path); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(path); if (esm) { await runtime.unstable_importModule(path); diff --git a/packages/jest-runtime/src/cli/index.ts b/packages/jest-runtime/src/cli/index.ts index 54857611e5c2..1214fdebea5b 100644 --- a/packages/jest-runtime/src/cli/index.ts +++ b/packages/jest-runtime/src/cli/index.ts @@ -94,7 +94,8 @@ export async function run( const runtime = new Runtime(config, environment, hasteMap.resolver); for (const path of config.setupFiles) { - const esm = runtime.unstable_shouldLoadAsEsm(path); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(path); if (esm) { await runtime.unstable_importModule(path); @@ -102,7 +103,8 @@ export async function run( runtime.requireModule(path); } } - const esm = runtime.unstable_shouldLoadAsEsm(filePath); + // TODO: remove ? in Jest 26 + const esm = runtime.unstable_shouldLoadAsEsm?.(filePath); if (esm) { await runtime.unstable_importModule(filePath);