Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly throw an error if jest-environment-jsdom is missing #12749

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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))
SimenB marked this conversation as resolved.
Show resolved Hide resolved

### Chore & Maintenance

Expand Down
7 changes: 6 additions & 1 deletion packages/jest-resolve/src/utils.ts
Original file line number Diff line number Diff line change
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