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

rootDir incorrectly set in Windows if using SUBST drive #8063

Closed
Mark-J-Lawrence opened this issue Mar 6, 2019 · 14 comments
Closed

rootDir incorrectly set in Windows if using SUBST drive #8063

Mark-J-Lawrence opened this issue Mar 6, 2019 · 14 comments

Comments

@Mark-J-Lawrence
Copy link

Mark-J-Lawrence commented Mar 6, 2019

🐛 Bug Report

I'm having problems using Jest in unison with VSCode (1.28.2) on a Windows 7 VDI machine provided by my employers.

We are asked to clone git repos onto our I: drives (as these are much faster). These I: drives actually appear to be created via the SUBST command from this folder C:\Users\<username>\Scratch, though this is supposed to be abstracted from everyone.

When I open a repo in VSCode, I do so from the I: drive location. When I then try to add breakpoints & debug, none of the breakpoints become verified.
In addition to this, when running the tests in the terminal from the I: drive location, the file paths in the coverage report are pointing to the C:\Users\<username>\Scratch location.

After a bit of a play I can see immediately that rootDir is being set to the C:\Users\<username>\Scratch location. I've tried to override this by setting it to the I: location in jest.config.js, but it doesn't seem to like me setting anything to a drive other than C:

If I then close VSCode and re-open the repo from the C: location, debugging works.

To Reproduce

  1. Create a a new drive from a folder on the C: drive using SUBST (https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst)
  2. Open VSCode
  3. Create a react app within the newly created drive
  4. Create a jest test
  5. Run Jest with coverage from the new drive
  6. Put a breakpoint in the jest test
  7. Run a jest debug config
  • Coverage paths are wrong
  • Breakpoints aren't hit

Expected behavior

  • The file paths in the coverage report should reflect working directory where the jest test was ran from.
  • Breakpoints are hit.
  • rootDir should be set to the project root in the current working directory path (not the location of the source folder the drive is mapped from.)

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

 System:
    OS: Windows 7
    CPU: (8) x64 Intel(R) Xeon(R) CPU E3-1585L v5 @ 3.00GHz
  Binaries:
    Node: 8.11.1 - C:\FAST\nodejs\8.11.1\node.EXE
    Yarn: 1.12.3 - C:\FAST\nodejs\8.11.1\yarn.CMD
    npm: 5.6.0 - C:\FAST\nodejs\8.11.1\npm.CMD
    jest: 24.1.0
@SimenB
Copy link
Member

SimenB commented Mar 6, 2019

Are you able to send a PR for it? None of the core team uses Windows, so we'll need help from the community on this one

We do call realpath, doesn't seem like it's enough: https://github.com/facebook/jest/blob/3e32813b1bf8c91dd59814322aa9552e7c0ab2a8/packages/jest-config/src/normalize.ts#L318

The info at the bottom doesn't include which Jest version you are using, could you add that?

@Mark-J-Lawrence
Copy link
Author

Ah sorry, description updated with Jest version.

I'll have a look and see if I can see something.

@Mark-J-Lawrence
Copy link
Author

Mark-J-Lawrence commented Mar 6, 2019

Stepping through the code, the line that is causing it is this one:

https://github.com/facebook/jest/blob/3e32813b1bf8c91dd59814322aa9552e7c0ab2a8/packages/jest-cli/src/cli/index.ts#L93

process.cwd() returns the correct path (e.g. I:\...), but using realpath then converts it to C:\..

I'm stepping through transpiled code, so realpath gets converted to _realpathNative etc

@SimenB
Copy link
Member

SimenB commented Mar 6, 2019

Ok, thanks! And following the link is wrong? That's odd. Seems like we should be realpathing more things then.

We went through and called realpath in a few places due to failures on CI (#7556 and linked issues). Maybe @willsmythe could chime in here?

@Mark-J-Lawrence
Copy link
Author

Mark-J-Lawrence commented Mar 6, 2019

I've followed it to this point:
https://github.com/SimenB/realpath-native/blob/7808c3d3d1d20b2314cc7bee788fc727f9f2f080/index.js#L34

It steps into that if condition because it finds fsBinding has a realpath function and line 36 returns the undesired path in the end.

I've looked at https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback and that gives me the impression it will resolve 'symbolic links', so I replaced line 36 with return fsBinding.realpathSync(filepath); and it worked.

I can't say this is the correct solution though as I'm not knowledgeable on fs stuff and what it might break, but my rootDir is now set correctly.

UPDATE: this only worked because an exception was being thrown and it went down to the final return, which worked for me

Mark-J-Lawrence added a commit to Mark-J-Lawrence/realpath-native that referenced this issue Mar 6, 2019
This is a fix for the bug reported here: jestjs/jest#8063

I'm not sure if this is the correct fix or not, it would be good to get verification before merge. Though Jest on my local machine is now operating correctly after this change.
@Mark-J-Lawrence
Copy link
Author

Mark-J-Lawrence commented Mar 6, 2019

I made a PR for a suggested code change (which I've since realised was garbage!)....

Currently I am removing the following lines locally. Jest functions correctly once I've done that:

https://github.com/SimenB/realpath-native/blob/7808c3d3d1d20b2314cc7bee788fc727f9f2f080/index.js#L32-L40

I've not created the PR for this as I don't think it's the right solution

@OliverCole
Copy link

@mjlawrence83 I have exactly the same issue. Did you get anywhere with this beyond the workaround you mentioned?

@dawnmil
Copy link

dawnmil commented Jun 20, 2021

Also having this issue. rootDir is returning C:/ drive location rather than I:/ drive which is the configured location of the project files in intellij. Was there a real fix for this?

@OliverCole
Copy link

Workaround: if you run subst, that will tell you the real location of your I: drive. If you point your shell/IntelliJ/etc at that directory instead, it may start working.

@dawnmil
Copy link

dawnmil commented Jun 21, 2021

Workaround: if you run subst, that will tell you the real location of your I: drive. If you point your shell/IntelliJ/etc at that directory instead, it may start working.

Yea that's what I did and it works... Just not a fan of changing my env variables to fit needs of one package. Hoping I haven't broken other things that were working. Fingers crossed.

Is this fixed in a later version of jest? I am on jest version 25.1.0

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jun 21, 2022
@github-actions github-actions bot removed the Stale label Jul 15, 2022
@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jul 15, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2023
@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 Sep 14, 2023
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