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

Jest-resolve broken: getMockModule throws an error #10771

Closed
FrontendMMA opened this issue Nov 2, 2020 · 11 comments · Fixed by #10779
Closed

Jest-resolve broken: getMockModule throws an error #10771

FrontendMMA opened this issue Nov 2, 2020 · 11 comments · Fixed by #10779

Comments

@FrontendMMA
Copy link

FrontendMMA commented Nov 2, 2020

💥 Regression Report

A clear and concise description of what the regression is.

Last working version

Worked up to version: 26.6.1

Stopped working in version: 26.6.2

To Reproduce

Steps to reproduce the behavior:

jest.config.js

'moduleNameMapper': {
    '^ui(.*)': '<rootDir>/ui$1',
}
import xSelector from "selectors/ui.selector.js"

throw error

Configuration error:

Could not locate module ui.selector mapped as:
/Users/xxx/Projects/xxx/src/ui$1.

Please check your configuration for these entries:
{
  "moduleNameMapper": {
    "/^ui(.*)/": "/Users/xxx/Projects/xxx/src/ui$1"
  },
  "resolver": undefined
}

Expected behavior

not throwed

Link to repl or repo (highly encouraged)

Run npx envinfo --preset jest

  System:
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 13.6.0 - ~/.nvm/versions/node/v13.6.0/bin/node
    Yarn: 1.21.1 - ~/.yarn/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v13.6.0/bin/npm
  npmPackages:
    jest: 26.1.0 => 26.1.0 

I can fix the regex, but the problem persists for others

This error here https://github.com/facebook/jest/blob/master/packages/jest-resolve-dependencies/src/index.ts#L78

@SimenB
Copy link
Member

SimenB commented Nov 2, 2020

From #10713 - @jeysal @brapifra ideas?

@SimenB
Copy link
Member

SimenB commented Nov 2, 2020

Should we just try-catch the getMockModule call?

@FrontendMMA do you have a reproduction we can pull down and test?

@brapifra
Copy link
Contributor

brapifra commented Nov 2, 2020

Sorry to see this regression! 😿

Should we just try-catch the getMockModule call? @SimenB
I think this should work. A reproduction would be certainly helpful.
Happy to open a PR if needed!

@FrontendMMA
Copy link
Author

Sorry, I can't provide the project
checked: try/catch works

image

@SimenB
Copy link
Member

SimenB commented Nov 2, 2020

Can you reduce it down? Just delete all code except the test file, the file it resolves to and the minimal jest config needed? A try/catch is not the correct solution I'd think - we shouldn't throw in the first place

@FrontendMMA
Copy link
Author

https://github.com/FrontendMMA/jest-resolve--bug-example

  1. change test file or tested file (App.js / App.test.js)
  2. execute jest -o (repeats in a "onlyChanged" mode)

@SimenB
Copy link
Member

SimenB commented Nov 2, 2020

Thanks @FrontendMMA! I had to change some stuff to make it work and understand where the regression was, I opened a PR: FrontendMMA/jest-resolve--bug-example#1

@brapifra would you be able to take a look at this? If you look at my branch it can be reproduced by removing the resolutions, running yarn and then follow the steps @FrontendMMA lists out in the comment above.

@brapifra
Copy link
Contributor

brapifra commented Nov 2, 2020

Yes, I will look into this tomorrow @SimenB

@SimenB
Copy link
Member

SimenB commented Nov 2, 2020

Thanks!

@SimenB
Copy link
Member

SimenB commented Nov 4, 2020

@github-actions
Copy link

This issue 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants