node -v: 12.18.0npm -v: 6.14.4yarn why jest❯ yarn why jest
└─ @yarnpkg/monorepo@workspace:.
└─ jest@npm:24.9.0 (via npm:^24.9.0)
your vscode-jest settings if customized:
Operating system: macOS 10.15.5
npm run test or node_modules/.bin/jest) yarn run jestClone the project https://github.com/yarnpkg/berry and open in vscode with vscode-jest extension installed. Go to Jest output.
[fill]
The getLocalPathForExecutable logic here does not consider yarn pnp configurations. The workaround is to manually specify the pathToJest but the correct behavior would be to properly resolve pnp binary. See https://github.com/yarnpkg/berry/pull/1440 for more info.
[fill]
vscode-jest should detect pnp and run yarn run jest instead of looking for a binary in node_modules
/bin/sh: jest: command not found
Finished running all tests. Starting watch mode.
/bin/sh: jest: command not found
/bin/sh: jest: command not found
/bin/sh: jest: command not found
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
/bin/sh: jest: command not found
The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...
this settings.json works.
{
"jest.pathToJest": "yarn jest"
}
@esetnik I'm having a look at this issue now. Do you have a good understanding of what you can look at in a repository to check that it is a Yarn PnP-based codebase? What I need to do is understand what conditions need to be met so that I can set the pathToJest command.
Things I can check:
.pnp.js file in repo root.yarn.lock file (and/or absence of package.lock file)workspaces)What I'm looking for is a fairly reliable way to identify if it is a pnp repo.
@rossknudsen I think it should first try node_modules/.bin, if fail check .pnp.js exists.
Adding "jest.pathToJest": "yarn jest" appears to fix running tests but not debugging them.
UPDATE:
Just found https://github.com/jest-community/vscode-jest/issues/618 which addresses this problem specifically.
This launch.json appears to work:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"runtimeExecutable": "yarn",
"runtimeArgs": ["run", "--inspect-brk", "jest", "--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
}
]
}
@OzzieOrca great to hear you got it resolved 👍 and sorry you had to struggle through it in the dark...
We just released a "Setup Wizard" in v4.0.0-alpha.5 that hopefully will streamline this process and spare the frustration. Please feel free to give it a try and let us know how it goes.
@esetnik instead of auto-detecting pnp, we now offered a "Setup Wizard" to help people customize their environment with simple steps. Would love to have you try it to see if it can setup the pnp env correctly: v4.0.0-alpha.5
Most helpful comment
this
settings.jsonworks.