Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(jest-config): throw correct error for missing preset modules #10737

Merged
merged 5 commits into from
Oct 31, 2020

Conversation

terite
Copy link
Contributor

@terite terite commented Oct 30, 2020

When loading a preset module that cannot be resolved (e.g. is not npm
installed), the following error is shown to users:

● Validation Error:

  Preset foobar is invalid:

  The "id" argument must be of type string. Received null

Instead, the following error should be shown

● Validation Error:

  Preset foobar not found.

This PR changes the error message by handling when
Resolver.findNodeModule returns null, indicating that the module cannot
be successfully imported.

Summary

The error currently presented when the preset module is missing is confusing, but also not the error intended to be shown.

For an example of confusion, see #10035

Test plan

  1. Updated jest-config tests pass
  2. Correct error is shown in local testing

To test yourself, add something like the following to your jest.config.js and observe the error message when running jest

  preset: 'foobar',

When loading a preset module that cannot be resolved (e.g. is not npm
installed), the following error is shown to users:

    ● Validation Error:

      Preset foobar is invalid:

      The "id" argument must be of type string. Received null

Instead, the following error should be shown

    ● Validation Error:

      Preset foobar not found.

This PR changes the error message by handling when
Resolver.findNodeModule returns null, indicating that the module cannot
be successfully imported.
packages/jest-config/src/__tests__/normalize.test.js Outdated Show resolved Hide resolved
} catch {}

// @ts-expect-error: `presetModule` can be null?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good stuff! 👍

@terite terite requested a review from SimenB October 30, 2020 23:53
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@SimenB SimenB merged commit 83c0828 into jestjs:master Oct 31, 2020
@terite terite deleted the jest-config-preset branch October 31, 2020 03:38
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants