Skip to content

Commit 83c0828

Browse files
authored
fix(jest-config): throw correct error for missing preset modules (#10737)
1 parent 8acfd38 commit 83c0828

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `[expect]` Stop modifying the sample in `expect.objectContaining()` ([#10711](https://github.com/facebook/jest/pull/10711))
1111
- `[jest-circus, jest-jasmine2]` fix: don't assume `stack` is always a string ([#10697](https://github.com/facebook/jest/pull/10697))
1212
- `[jest-config]` Fix bug introduced in watch mode by PR [#10678](https://github.com/facebook/jest/pull/10678/files#r511037803) ([#10692](https://github.com/facebook/jest/pull/10692))
13+
- `[jest-config]` Throw correct error for missing preset modules ([#10737](https://github.com/facebook/jest/pull/10737))
1314
- `[jest-resolve-dependencies]` Resolve mocks as dependencies ([#10713](https://github.com/facebook/jest/pull/10713))
1415
- `[jest-runtime]` Handle file URLs in dynamic imports ([#10744](https://github.com/facebook/jest/pull/10744))
1516

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ describe('preset', () => {
954954
return '/node_modules/react-native-js-preset/jest-preset.js';
955955
}
956956

957-
if (name === 'doesnt-exist') {
957+
if (name.includes('doesnt-exist')) {
958958
return null;
959959
}
960960

packages/jest-config/src/normalize.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,15 @@ const setupPreset = (
133133
);
134134

135135
try {
136+
if (!presetModule) {
137+
throw new Error(`Cannot find module '${presetPath}'`);
138+
}
139+
136140
// Force re-evaluation to support multiple projects
137141
try {
138-
if (presetModule) {
139-
delete require.cache[require.resolve(presetModule)];
140-
}
142+
delete require.cache[require.resolve(presetModule)];
141143
} catch {}
142144

143-
// @ts-expect-error: `presetModule` can be null?
144145
preset = require(presetModule);
145146
} catch (error) {
146147
if (error instanceof SyntaxError || error instanceof TypeError) {

0 commit comments

Comments
 (0)