node -v: 8.9.4npm -v: 5.6.0npm ls react-scripts (if you haven鈥檛 ejected): [email protected]
Operating system: OSX 10.13.2
vscode-jest installednpx create-react-app my-appcd my-app && yarn add @types/jest.vscode/launch.json file and add the following configuration, from the create-react-app readme. {
"version": "0.2.0",
"configurations": [
{
"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"args": [
"test",
"--runInBand",
"--no-cache",
"--env=jsdom"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
source: https://github.com/facebook/create-react-app/blob/ed5c48c81b2139b4414810e1efe917e04c96ee8d/packages/react-scripts/template/README.md#debugging-tests-in-visual-studio-code
src/App.test.jsit('SIMPLE TEST', () => {
let x = 1;
let y = 2;
expect(1).toEqual(2);
});
Debug lens above the test. The debug overlay to open and the debugger to break.
Error: Cannot find jest.js file
Note: Following some research elsewhere on this issue queue and elsewhere I've also tried setting my jest.pathToJest in my .vscode/settings.json to a number of different settings with no luck.
Reference:
ha - seems that modifying the settings.json file to the following works:
{
"jest.pathToJest": "node_modules/jest/bin/jest.js"
}
UPDATE: - Unfortunately, import statements now seem to fail in the tests.
Well that's confusing, I was thinking it was the same as #193.
Hey! So I was experiencing the exact same problem, and it turned out I needed to add a .babelrc to the root of my project with just the following:
{
"presets": [
"react-app"
]
}
You may need to restart vscode, but I'm not totally sure.
Hi !
I'm having the same issue, even with a .babelrc as described by @beaksandclaws. What is the right config for jest.pathToJest ? Or is this more than just finding the right config ?
Alain
Maybe this extension is running jest directly instead of using react-scripts.
Which causes problems because react-scripts introduce configurations for ES6/jsx syntax. Which is why @justinlevi got a problem with imports.
Here's a screen capture video showing the issue plus the "fix" by manually editing the jest.pathToJest to "node_modules/jest/bin/jest.js". Unfortunately I have to switch back this setting as soon as I'm done debugging otherwise I get the module import errors.

This is the same issue as #193. Directly suppling jest to pathToJest doesn't work (same as simply running jest in a terminal outside of VS Code), since react-scripts adds a pile of configuration for jest.
For your information, #271 should bring support for debugging projects created by create-react-app.
I'm closing it since it got resolved with today's update.
Hey! So I was experiencing the exact same problem, and it turned out I needed to add a
.babelrcto the root of my project with just the following:{ "presets": [ "react-app" ] }You may need to restart vscode, but I'm not totally sure.
That's worked for me. Thank you. Seems like it is the easiest solutions.
In same way, and for those who don't like having a lot of configuration file at root of their projects, you can add this to your package.json:
"babel": {
"presets": [
"react-app"
]
}
Most helpful comment
Hey! So I was experiencing the exact same problem, and it turned out I needed to add a
.babelrcto the root of my project with just the following:You may need to restart vscode, but I'm not totally sure.