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

The meaning of the root path parameter #571

Closed
garyee opened this issue Apr 16, 2020 · 4 comments
Closed

The meaning of the root path parameter #571

garyee opened this issue Apr 16, 2020 · 4 comments

Comments

@garyee
Copy link

garyee commented Apr 16, 2020

Environment

  1. node -v: v10.16.2

  2. npm -v: 6.10.3

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@24.9.0

  4. your vscode-jest settings if customized:

    • jest.pathToJest? D:/myproject/Frontend/app/node_modules/.bin/jest
    • jest.pathToConfig? D:/myproject/Frontend/app/jest.config.js
    • anything else that you think might be relevant?
  5. Operating system: Win 10

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Steps to Reproduce

  • create a react project with the following structure:

  • projectfolder (myproject)

    • Backend/
    • Frontend/
      • app/ (npm root)
        • node_modules/ (generated by npm)
        • jest.config.js
        • src/ this is where the code goes
  • jest.pathToJest? npm test

  • jest.pathToConfig? D:/myproject/Frontend/app/jest.config.js

Relevant Debug Info

ERR! enoent ENOENT: no such file or directory, open 'd:\myproject\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xxxx\AppData\Roaming\npm-cache\_logs\2020-04-16T05_45_58_741Z-debug.log

Starting Jest in Watch mode failed too many times and has been stopped.
 see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting

Expected Behavior

I got the above error and I thought: "this is what Root Path" is for, even if I was confused by the desciption. So that he would not try to find the package.json in the root of my project (d:\myproject) but in the "npm root".

Then I put in the config:

  • "jest.rootPath": "D:/myproject/Frontend/app/",

Which gave me another error instead:

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT
Finished running all tests. Starting watch mode.

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT

Exception raised: Process failed: spawn C:\WINDOWS\system32\cmd.exe ENOENT
Starting Jest in Watch mode failed too many times and has been stopped.
 see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.

It took me a while to come back to the jest.rootPath parameter. And when I deleted it, I got the first error back, which I resolved by not using "npm test" but "D:/myproject/Frontend/app/node_modules/.bin/jest" for pathToJest, which caused another problem that does not seem to be related to the usage or configuration of this project.

What purpose serves the rootPath parameter? I've read in other issues that people did wonder.
It does not seem to denote the path to the folder I call npm root, which is what I had hoped for.
If it is to denote the path to the script files? Isn't this what a jest.config is for and wouldn't the two cancel each other out or something?

I have the problem that if I start my tests with "npm test" it goes like expected but If I run them with the excecutable (D:/myproject/Frontend/app/node_modules/.bin/jest) they all fail because of some error that originates from within my configuration or jest or else...
And it is the same on console or VS Code.
So that's why I would like to use "npm run", but I can't

@connectdotz
Copy link
Collaborator

try to set your jest.pathToJest to npm run test... yeah I know the name is not intuitive...

@connectdotz connectdotz mentioned this issue Apr 28, 2020
15 tasks
@seanpoulter seanpoulter added this to the v4.0 milestone May 2, 2020
@seanpoulter
Copy link
Member

Cross-referencing jest-community/jest-editor-support#44.

@connectdotz
Copy link
Collaborator

re-reading this issue makes me wonder if there is a bug with rootPath on windows... Setting rootPath to "D:/myproject/Frontend/app/" should be correct, this will set the cwd of the jest node process with that directory instead of "D:/myproject". Anyway, I know this issue has been a while, if anyone has a sample repo we are happy to take a look.

Meanwhile, feel free to give the latest v4.0.0-alpha.5 release a try, which fixed quite a few issues accumulated through the years.

@connectdotz connectdotz removed this from the v4.0 milestone Jan 14, 2024
@connectdotz
Copy link
Collaborator

Closed due to inactivity and accumulated changes over time, possibly making it outdated. Feel free to reopen if it remains relevant.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants