Skip to content

Commit

Permalink
fix(jest-config): throw correct error for missing preset modules (#10737
Browse files Browse the repository at this point in the history
)
  • Loading branch information
terite committed Oct 31, 2020
1 parent 8acfd38 commit 83c0828
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
- `[expect]` Stop modifying the sample in `expect.objectContaining()` ([#10711](https://github.com/facebook/jest/pull/10711))
- `[jest-circus, jest-jasmine2]` fix: don't assume `stack` is always a string ([#10697](https://github.com/facebook/jest/pull/10697))
- `[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))
- `[jest-config]` Throw correct error for missing preset modules ([#10737](https://github.com/facebook/jest/pull/10737))
- `[jest-resolve-dependencies]` Resolve mocks as dependencies ([#10713](https://github.com/facebook/jest/pull/10713))
- `[jest-runtime]` Handle file URLs in dynamic imports ([#10744](https://github.com/facebook/jest/pull/10744))

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -954,7 +954,7 @@ describe('preset', () => {
return '/node_modules/react-native-js-preset/jest-preset.js';
}

if (name === 'doesnt-exist') {
if (name.includes('doesnt-exist')) {
return null;
}

Expand Down
9 changes: 5 additions & 4 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -133,14 +133,15 @@ const setupPreset = (
);

try {
if (!presetModule) {
throw new Error(`Cannot find module '${presetPath}'`);
}

// Force re-evaluation to support multiple projects
try {
if (presetModule) {
delete require.cache[require.resolve(presetModule)];
}
delete require.cache[require.resolve(presetModule)];
} catch {}

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

0 comments on commit 83c0828

Please sign in to comment.