From 362c6f8bf539e805365bec460875acf89c0e218f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 26 Apr 2022 11:01:03 +0200 Subject: [PATCH 1/4] fix: correctly throw an error if jest-environment-jsdom is missing --- CHANGELOG.md | 1 + packages/jest-resolve/src/utils.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d0b68cddb7..bce19e24acb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[jest-circus]` Improve `test.concurrent` ([#12748](https://github.com/facebook/jest/pull/12748)) +- `[jest-resolve]` Correctly throw an error if jsdom env is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749)) ### Chore & Maintenance diff --git a/packages/jest-resolve/src/utils.ts b/packages/jest-resolve/src/utils.ts index e695343003a3..7a55cdd2c1a4 100644 --- a/packages/jest-resolve/src/utils.ts +++ b/packages/jest-resolve/src/utils.ts @@ -98,6 +98,11 @@ export const resolveTestEnvironment = ({ testEnvironment: string; requireResolveFunction: (moduleName: string) => string; }): string => { + // we don't want to resolve the actual `jsdom` env if `jest-environment-jsdom` is not installed + if (filePath === 'jsdom') { + filePath = 'jest-environment-jsdom'; + } + try { return resolveWithPrefix(undefined, { filePath, @@ -108,7 +113,7 @@ export const resolveTestEnvironment = ({ rootDir, }); } catch (error: any) { - if (filePath === 'jsdom' || filePath === 'jest-environment-jsdom') { + if (filePath === 'jest-environment-jsdom') { error.message += '\n\nAs of Jest 28 "jest-environment-jsdom" is no longer shipped by default, make sure to install it separately.'; } From 2507fa2283ccc98ef04216de95ce6a9c7a4118dd Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 26 Apr 2022 11:08:47 +0200 Subject: [PATCH 2/4] ticks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bce19e24acb9..8069ca5c1982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - `[jest-circus]` Improve `test.concurrent` ([#12748](https://github.com/facebook/jest/pull/12748)) -- `[jest-resolve]` Correctly throw an error if jsdom env is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749)) +- `[jest-resolve]` Correctly throw an error if `jsdom` env is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749)) ### Chore & Maintenance From e5fc506c19bd53e439ce66d56e9051bc14892901 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 26 Apr 2022 11:10:58 +0200 Subject: [PATCH 3/4] Update packages/jest-resolve/src/utils.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- packages/jest-resolve/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-resolve/src/utils.ts b/packages/jest-resolve/src/utils.ts index 7a55cdd2c1a4..969b5b299492 100644 --- a/packages/jest-resolve/src/utils.ts +++ b/packages/jest-resolve/src/utils.ts @@ -98,7 +98,7 @@ export const resolveTestEnvironment = ({ testEnvironment: string; requireResolveFunction: (moduleName: string) => string; }): string => { - // we don't want to resolve the actual `jsdom` env if `jest-environment-jsdom` is not installed + // we don't want to resolve the actual `jsdom` module if `jest-environment-jsdom` is not installed, but `jsdom` package is if (filePath === 'jsdom') { filePath = 'jest-environment-jsdom'; } From 85faa4e54133b370e339ad78e3f655d5e9db2fdd Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 26 Apr 2022 11:18:24 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8069ca5c1982..31b4deb0c4de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - `[jest-circus]` Improve `test.concurrent` ([#12748](https://github.com/facebook/jest/pull/12748)) -- `[jest-resolve]` Correctly throw an error if `jsdom` env is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749)) +- `[jest-resolve]` Correctly throw an error if `jsdom` test environment is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749)) ### Chore & Maintenance