jest: `node --inspect-brk jest --runInBand --watch` doesn't stop on breakpoint or debugger statement.
🐛 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
module.exports = {
globals: {
"ts-jest": {
skipBabel: true,
enableTsDiagnostics: true,
disableSourceMapSupport: true
}
},
roots: [
"<rootDir>/src",
"<rootDir>/tests"
],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "(/tests/.*.(test|spec)).ts$",
moduleFileExtensions: [
"js",
"ts",
"json",
"node"
],
setupTestFrameworkScriptFile: "jest-extended",
verbose: true
};
Expected behavior
I would expect debugging to work with --watch
Run npx envinfo --preset jest
it errors with
(node:2536) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
node --version
v10.0.0
jest version
23.4.0
Thanks
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 31
- Comments: 38 (14 by maintainers)
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
--no-cache
when invoking Jest. This also seems to solve the problem with the latest Jest release too. It’s not clear to me why just downgrading Jest to the version that had been working reliably before didn’t work, but there are so many moving parts that have changed in last few weeks (VS Code version, typescript, jest, ts-jest) I assume there are other things involved.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.
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:
I assume #6647 causes this issue.
runInBand is backlisted when watching. This also breaks debugging in watch mode for me. Removing
--watch
and only using--runInBand
works, but slows me down, because jest startup has to paid every time, while restarting tests in watch mode is faster.I would say always use workers in watch mode expect when passing
--runInBand
.cc @mjesun
This is still an issue for in
v27.0.3
After much experimentation, I was able to get TypeScript spec debugging working with VSCode and Jest v24.x.
My setup:
Launch.json:
Jest is configured with preset
ts-jest/presets/js-with-ts
.TypeScript is configured with
"sourceMap": true
.Note that even watch is working!
@jamietre
I’ve scaled my test back to this:
I’m running
yarn test:debug aTest.test.js
from this package.jsonChrome will pause here:
And in my terminal stops here:
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.
Is this still an issues in Jest 25? We’ve had a few fixed to source map handling in the last few releases
Same, the trigger is the ‘–watch’ flag. Running without it makes breakpoints and
debugger
hithow about just
NODE_OPTIONS="--inspect-brk"
?Note: Use VS Code if you can! (see here) It’s way faster and less finnicky than
ndb
.The
ndb
solutionUsing ndb, we can debug child processes (so
--runInBand
should not be used). Breakpoints anddebugger
statements are respected. 😃note: You may need to set a breakpoint before your
debugger
statements are respected. 😦Directions
npm install -g ndb
"debug": "jest --watch"
to your NPM scriptsndb
(no args) from your package’s root directoryndb
(see here)Cheers man
https://github.com/facebook/jest/blob/fb2a6ac4d3f4e9530941e24030b52f3d506aa2de/packages/jest-cli/src/TestScheduler.js#L88-L94
What do you say about checking
process.execArgv
, look for--inspect
/--inspect-brk
andrunInBand
as a result?Do we have a reason not to
runInBand
while debugging?