Skip to content

Commit 77f3cdb

Browse files
bentcpojer
authored andcommitted
Stop using Node --inspect option in the docs on debugging (jestjs#1998)
The technique described in the instructions does not pick up breakpoints set with `debugger` statements. This issue is being tracked by jestjs#1652, but it's unclear how long it will take to resolve as it's actually a Node issue. As a work-around, have updated docs to describe connecting an external debugger to the Node process.
1 parent 50e1cf6 commit 77f3cdb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/Troubleshooting.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@ Uh oh, something went wrong? Use this guide to resolve issues with Jest.
1111

1212
### Tests are Failing and You Don't Know Why
1313

14-
Try using the debugger built into >= Node 6.3.
14+
Try using the debugging support built into Node.
1515

1616
Place a `debugger;` statement in any of your tests, and then, in your project's directory, run:
1717

18-
`node --debug-brk --inspect ./node_modules/.bin/jest -i [any other arguments here]`
18+
`node --debug-brk ./node_modules/.bin/jest -i [any other arguments here]`
19+
20+
This will run Jest in a Node process that an external debugger can connect to. Note that the process
21+
will pause until the debugger has connected to it.
22+
23+
For example, to connect the [Node Inspector](https://github.com/node-inspector/node-inspector)
24+
debugger to the paused process, you would first install it (if you don't have it installed already):
25+
26+
`npm install -g node-inspector`
27+
28+
Then simply run it:
29+
30+
`node-inspector`
1931

2032
This will output a link that you can open in Chrome. After opening that link, the Chrome Developer Tools will be displayed, and a breakpoint will be set at the first line of the Jest CLI script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the `debugger` statement, execution will pause and you can examine the current scope and call stack.
2133

2234
*Note: the `-i` cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.*
2335

24-
More information on the V8 inspector can be found here: https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js
36+
More information on Node debugging can be found here: https://nodejs.org/api/debugger.html
2537

2638
### Caching Issues
2739

0 commit comments

Comments
 (0)