-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
node --inspect-brk jest --runInBand --watch
doesn't stop on breakpoint or debugger statement.
#6683
Comments
I'm having a similar problem.
|
I'm having this problem also. At first I thought it was Visual Studio Code issue; there seems to be a problem with debugging in the latest release as well which confuses things further. But the workarounds and downgrading vscode didn't work for me. I had to downgrade Jest to 22.4.4 to get debugging to work correctly again. This could also be a ts-jest issue, since I've been unable to run ts-jest@23 for different reasons.
|
@jamietre Thanks! The latest packages weren't working for me but that combination does! For the sake of any others, here is my config: Packages
Webstorm steps
jest.config.js
|
@mgibson91 I ended up at Jest 23.1.0. There are some behavior changes between 22.4.4 and 23.1.0 (bug fixes perhaps?) related to mock resolution when writing typescript mocks for javascript files, which we had explicit tests for because it was confusing. So that may not matter to you but just wanted to let you know everything works at least up to 23.1.0 (with ts-jest 22.4.6) for us. |
@jamietre Good to know, thanks! |
I started having trouble again after downgrading to 23.1.0, and after pulling some hair out I got things to work reliably by using I tried the following:
Breakpoints are unverified. Debugging doesn't work at all
Breakpoints are verified. Stops on breakpoints the first run only. After changing something resulting in tests restarting, vscode still shows verified breakpoints, but the debugger doesn't work any more.
Seems to work reliably. So there's something wrong with the way sourcemaps are cached, apparently, and it isn't just old/invalid cached information lying around from an older version of something, since clearing the cache only results in it working once. |
thanks @mgibson91, the versions you provided work for me:
running the following command: $ node --inspect $(npm bin)/jest --watch Breakpoints were not being hit when using |
I assume #6647 causes this issue.
runInBand is backlisted when watching. This also breaks debugging in watch mode for me. Removing I would say always use workers in watch mode expect when passing cc @mjesun |
What do you say about checking Do we have a reason not to |
Hi awesome Jest team, Thank you for your wonderful efforts to make our coding workflows better. I unfortunately suffer from the same issue with the following versions:
Here is my jest.config.json:
And this is my script to run tests:
Breakpoints only hit and stop if I have a single test file. However, with multiple test files, no breakpoint is respected, including using Any clue is appreciated. Thank you! |
If you're in |
Jest definitely doesn't disable My problem was always when running just one test, and I was able to fix it only by disabling the cache. I am guessing there are more things at play here then just In any event, this certainly seems to be involved somehow. EIther way I think Jest should fail if someone tries to use incompatible options instead of just "blacklisting" it, resulting in very confusing outcomes. |
Thank you guys for your prompt answers. Just being digressive here, how does your debugging workflow with Jest look like then? Do you switch back and forth between Jest output and manual CLI to debug failed ones one by one? How can this be more effective? Thank you again for your help! |
It's not typical for me to have more than a single test that needs debugging at one time; having Jest debugging only work for one test doesn't seem like that big a deal to me (if indeed that's the only problem here). That is - I wouldn't usually start work on a new test while an existing one was broken. If I happened to have some regression that broke lots of things, I'd just pick one to deal with, and fixing the underlying issue would likely fix them all. The bigger issue (for me anyway) is that it's been very confusing to understand why it wasn't working and get it to work reliably. |
Cheers man |
Ran into this, took about 5 hours thinking my VSCode was malfunctioning. If anyone else has a workflow of running jest in watch mode, then using VSCode to "Attach by Process ID", I recommend modifying your command line to:
|
This is required for VSCode users to be able to debug from within VSCode. See: jestjs/jest#6683 (comment)
No idea why, but this stopped working for me now. I think it's something to do with the workers being created when in watch mode. I don't think there is a way to prevent it now. Maybe I'm missing something. |
@ravihugo I can confirm that I guess for now we need to pick if we want watch mode or breakpoints |
This seems like a very important issue. Could we please get a Jest core contributor to look into this deeper?
Should we consider bundling Jest using Rollup for faster startup performance? Or maybe Yarn PNP can be utilized here? |
Note: Use VS Code if you can! (see here) It's way faster and less finnicky than The
|
I also can't get debuggers to catch using chrome node devtools, the solutions above don't seem to work. The initial breakpoint is caught but none of the debuggers I'm putting into the actual file are catching. |
You're absolutely sure you're only running Jest against one file at a time?
.. with only one test continues to work fine for me, on latest release of Jest 23.6.0. Running only one test is very important. |
I've scaled my test back to this:
I'm running {
"scripts": {
"test": "jest --colors",
"test:debug": "node --inspect-brk node_modules/.bin/jest --watch --no-cache --runInBand"
},
"jest": {
"verbose": true,
"collectCoverage": false,
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.2.0",
"@babel/plugin-transform-object-assign": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-bridge",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.0",
"jest": "^23.6.0",
"regenerator-runtime": "^0.12.1",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
}
} Chrome will pause here: (function (exports, require, module, __filename, __dirname) {
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const importLocal = require('import-local');
if (!importLocal(__filename)) {
require('jest-cli/bin/jest');
}
}); And in my terminal stops here:
|
how about just |
@benterprise if I am not mistaken that does not satisfy the criteria of "running only one test". Jest is still going to disable Try again using a pattern as the final command line argument that will result in only a single test file being matched. |
I was encountering a similar issue running just via
|
debugger wasn't stopping for me. I read through most of this thread and needed to watch for changes. I'm using just running one spec and passing the no-cache flag worked for me
|
Same, the trigger is the '--watch' flag. Running without it makes breakpoints and |
After much experimentation, I was able to get TypeScript spec debugging working with VSCode and Jest v24.x. My setup:
Launch.json: {
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug unit tests",
"runtimeArgs": [
"--inspect-brk",
"--nolazy",
"node_modules/jest/bin/jest",
"--runInBand",
"--watch",
"--config=path/to/jest.config.json",
],
"sourceMaps": true,
"disableOptimisticBPs": true,
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229,
"env": {
"NODE_ENV": "test"
}
}
]
} Jest is configured with preset TypeScript is configured with Note that even watch is working! |
This worked for me. {
"type": "node",
"request": "launch",
"name": "Watch Jest Current File",
"runtimeArgs": [
"--inspect-brk",
"--nolazy",
"${workspaceFolder}/node_modules/.bin/jest",
"${fileBasenameNoExtension}",
"--colors",
"--watch",
"--runInBand",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"sourceMaps": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
},
"port": 9229
} |
Is this still an issues in Jest 25? We've had a few fixed to source map handling in the last few releases |
This is still an issue for in |
Seems like
something similar happens runnig with
but I found that running
|
I am getting a similar error:
Testing with node v10.16.0. |
I confirm that node debugger mode does not start Jest. Testing with node v16.13.0:
I also tried with Jest binary (as document): PS: There is no error output. |
I have same issue as @anthonyvialleton, node v16.13.0, MacOS Monterey |
OP reports This issue is more than 3.5 years old at this point, and has had lots of examples and workarounds it's hard to say what the current state is. So I'll close this and ask anyone still having issues to open up a new issue with minimal reproduction steps (i.e. no VS code, no CRA etc.). I realise this is a sucky message, but the issue in the OP is fixed, so a new issue should be filed with any new issues with debugging. Anecdotally, debugging works fine for me using chrome with watch mode, so it's not completely broken. |
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. |
🐛 Bug Report
node --inspect-brk jest --runInBand --watch
doesn't stop on breakpoints or debugger statement whereas
node --inspect-brk jest --runInBand
will (no --watch flag)
Noe: It is using ts-jest 23.0.0
jest.config.js
Expected behavior
I would expect debugging to work with --watch
Run
npx envinfo --preset jest
it errors with
Thanks
The text was updated successfully, but these errors were encountered: