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

process.cwd is not mocked for path.resolve #5146

Closed
borodean opened this issue Dec 20, 2017 · 7 comments
Closed

process.cwd is not mocked for path.resolve #5146

borodean opened this issue Dec 20, 2017 · 7 comments

Comments

@borodean
Copy link

borodean commented Dec 20, 2017

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

What is the current behavior?
path.resolve ignores mocked process.cwd.

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.

Demo: https://repl.it/@borodean/jest-issue-process-cwd

What is the expected behavior?
path.resolve should resolve from the mocked current directory.

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

Jest 22.0.3
node 8.9.3
npm 5.6.0
Ubuntu 16.04.3 LTS

@borodean
Copy link
Author

Here is the place in path.resolve source code that references process.cwd:
https://github.com/nodejs/node/blob/08941e9f1b3f1e8214e0a23d02b19bb07de8b951/lib/path.js#L203

@borodean
Copy link
Author

Demo of how it works in vanilla node: https://repl.it/@borodean/jest-issue-process-cwd-node

@SimenB
Copy link
Member

SimenB commented Dec 21, 2017

@mjesun is this some issue with globals being injected and some not? Ref #2549

@mjesun
Copy link
Contributor

mjesun commented Dec 22, 2017

Yep; looks like it's caused by the fact that the process object on a test is not the real one, but a mocked version. Since all Node modules are required from the outer context (we tried fixing this in #4970, but we had to rollback as it's not mature enough yet), when you override process.cwd it's not the real one 😞.

@SimenB
Copy link
Member

SimenB commented Dec 22, 2017

Closing as dupe of #2549 then

@SimenB SimenB closed this as completed Dec 22, 2017
@nidkil
Copy link

nidkil commented Apr 29, 2019

@SimenB sorry to react to a closed issue, but I looked at the referenced issue and cannot figure out how the two are related and if any progress has been made. I'm running into the same problem with mocking process.cwd and process.resolve. Has any progress been made or is there a workaround available?

@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

No branches or pull requests

4 participants