question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Run Jest inside sub-folder

See original GitHub issue

image

I’m getting this error when trying to watch jest: command 'extension.jest.startJest' not found

So, after I installed the extension, nothing happens: image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:27 (14 by maintainers)

github_iconTop GitHub Comments

5reactions
Domiiicommented, Nov 23, 2019

Also having that problem. Jest Debug Console says:

Exception raised: Process failed: spawn jest ENOENT

Took me a while, but I finally figured it out:

Final solution

  1. Create new runJest.sh file (in workspace root)
  2. In my case, it contains: cd relative/path/to/project && npm test # NOTE: path contains package.jsonand have atest script defined
  3. In VSCode’s settings.json, add: "jest.pathToJest": "sh runJest.sh"
  4. Runs super smooth!

Making the Debugger work as well

When pressing “Debug” next to a test, things still error out, so what to do?

As they point out in “How to I debug tests?”, you need to add a custom test runner config in launch.json which MUST contain name: "vscode-jest-tests". I added this (and it works!!):

{
	"type": "node",
	"request": "launch",
	"name": "vscode-jest-tests",
	"program": "${workspaceRoot}/projects/todomvc/examples/vanilla-es6/node_modules/jest/bin/jest.js",
	"cwd": "${workspaceRoot}/projects/todomvc/examples/vanilla-es6",
	"args": [
		"--i",
		"--config",
		"jest.config.js"
	]
}

(NOTE: This even works on Windows if you have Cygwin installed and properly configured)

Problem Solving Process

  1. The official vscode-jest troubleshooting guide tells you to set your workspace’s jest.pathToJest setting, however there is no documentation on how its supposed to work.
  2. Looked at the source code and saw one special case returning npm test --, realizing it’s actually ill-named: it’s a command-line/shell command and not a path.
    • Turns out that jest from the error message (spawn jest ENOENT) refers to the value of pathToJest.
  3. First I tried (in my sample project): "jest.pathToJest": "cd projects/todomvc/examples/vanilla-es6/ && npm test".
    • No dice. It cannot handle chained commands. This post probably would fix that.
    • Also note that VSC project variables/macros (such as ${workspaceFolder}) won’t be recognized (at least it did not when I tried, might just be a temporary bug)
  4. Finally came up with final solution mentioned above.
3reactions
luizboncommented, Nov 28, 2016

After the last update, still not working for me. 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run Jest tests only for current folder - Stack Overflow
For e.g. if I go to c:/dev/app in terminal and type some-jest-command , it should only run files with .test.js present in the...
Read more >
How to run tests only from a specific directory in Jest? Define ...
How to run tests only from a specific directory in Jest? Define your test files pattern with KNAPSACK_PRO_TEST_FILE_PATTERN. You can modify a default...
Read more >
Configuring Jest
When the projects configuration is provided with an array of paths or glob patterns, Jest will run tests in all of the specified...
Read more >
Running Tests in Subdirectories - Laracasts
Running Tests in Subdirectories. I would like to organize my tests using subdirectories rather than just all in the root ./tests directory.
Read more >
[Solved]-Jest takes more time if jest.config.js is in subfolder or ...
Coding example for the question Jest takes more time if jest.config.js is in subfolder or subdirectory-Vue.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found