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's require looks for modules in different order than Node.js #5377

Closed
vlasy opened this issue Jan 23, 2018 · 5 comments · Fixed by #5403
Closed

Jest's require looks for modules in different order than Node.js #5377

vlasy opened this issue Jan 23, 2018 · 5 comments · Fixed by #5403

Comments

@vlasy
Copy link
Contributor

vlasy commented Jan 23, 2018

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Jest looks for modules first in modulePaths and then in node_modules folder

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

  1. Clone this repo
  2. Install packages - yarn install
  3. Run tests - yarn test

What is the expected behavior?
Jest would firstly look for modules in node_modules and then in modulePaths. It works this way in classic Node.js - first look in node_modules and then in NODE_PATH.
Therefore console.log in dummy.test.js should print <rootDir>/node_modules/passport/lib/index.js. But it prints <rootDir>/config/passport.js

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest - 22.1.4
node - 6.12.2
yarn - 1.3.2
npm - 3.10.10
OS - Ubuntu 16.04.3 LTS

@vlasy vlasy changed the title Jest require look for modules in different order than Node.js Jest's require looks for modules in different order than Node.js Jan 23, 2018
@SimenB
Copy link
Member

SimenB commented Jan 24, 2018

Could you send a PR with a fix and test? The implementation is here: https://github.com/facebook/jest/blob/79086eedaaec453d99002971680e55f560072a29/packages/jest-runtime/src/index.js#L270-L336

@vlasy
Copy link
Contributor Author

vlasy commented Jan 25, 2018

Hi, I made a fork and tried running the tests before I made any changes (as described in "contributing" docs here) and this was the output:

Snapshot Summary
 › 532 snapshot tests failed in 17 test suites. Inspect your code changes or run `yarn run jest -u` to update them.

Test Suites: 17 failed, 204 passed, 221 total
Tests:       421 failed, 1 skipped, 1479 passed, 1901 total
Snapshots:   532 failed, 183 passed, 715 total
Time:        243.363s

Is this...not ok, but at least expected?

@SimenB
Copy link
Member

SimenB commented Jan 25, 2018

That's not expected... Are you on the latest version of yarn (1.3.2)? If yes, can you pass -u to see what sort of changes it wants? It seems like it's unable to write/read snapshots at all

@vlasy
Copy link
Contributor Author

vlasy commented Jan 27, 2018

PR sent

@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 13, 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.

2 participants