Skip to content

Commit

Permalink
fix: correctly throw an error if jest-environment-jsdom is missing (j…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and F3n67u committed May 2, 2022
1 parent d201270 commit a8bf073
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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` test environment is used, but not installed ([#12749](https://github.com/facebook/jest/pull/12749))

### Chore & Maintenance

Expand Down
7 changes: 6 additions & 1 deletion packages/jest-resolve/src/utils.ts
Expand Up @@ -98,6 +98,11 @@ export const resolveTestEnvironment = ({
testEnvironment: string;
requireResolveFunction: (moduleName: string) => string;
}): string => {
// 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';
}

try {
return resolveWithPrefix(undefined, {
filePath,
Expand All @@ -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.';
}
Expand Down

0 comments on commit a8bf073

Please sign in to comment.