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

support require.resolve options #6206

Closed
MichaelDeCorte opened this issue May 18, 2018 · 1 comment · Fixed by #6471
Closed

support require.resolve options #6206

MichaelDeCorte opened this issue May 18, 2018 · 1 comment · Fixed by #6471

Comments

@MichaelDeCorte
Copy link

MichaelDeCorte commented May 18, 2018

🚀 Feature Proposal

node v8.9.0 added the options argument to require.resolve.
https://nodejs.org/api/modules.html#modules_require_resolve_request_options

jest does not support the options argument

It would also be good to support require.resolve.paths which I understand from @SimenB is not supported

https://nodejs.org/api/modules.html#modules_require_resolve_paths_request

Motivation

Jest should stay current with node's implementation for overridden methods.

Example

**Link to repl or repo **

https://repl.it/@mdecorte/LightsalmonNutritiousNaturaldocs

Code Snippet
Below is a code snipped from the above rep that works in node but not jest

let paths = {
    'paths':
    [
        './dir'
    ]
};

let fName = 'bar.js';
let fPath = require.resolve(fName, paths);
let f = require(fPath);
f();

To Reproduce
compare output from repo between node foo-test.js vs jest foo-test.js

Expected behavior

    $ node foo-test.js
    f>>>
    hi
    <<<f

Actual behavior

$ jest foo.test.js
  console.log foo-test.js:10
    f>>>

  console.log foo-test.js:20
    _error: Error: Cannot find module 'bar.js' from 'foo-test.js'_

Misc
$ jest --version
v22.4.3

a workaround is to add to jest.config.js

module.exports= {
    "moduleDirectories": [
     './dir'
    ].concat(module.paths)
}; 

This was originally Defect #6201

@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 12, 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