Skip to content

Commit

Permalink
fix: correctly throw an error if jest-environment-jsdom is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 26, 2022
1 parent d9f6aaf commit 362c6f8
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 env 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` env if `jest-environment-jsdom` is not installed
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 362c6f8

Please sign in to comment.