~1 min read|
In Debugging Node, I discussed how to use Node’s
--inspect flag to debug a Node process.
This is also really helpful for when we want to step through a Jest process and debug it without inserting a lot of console statements.
Within the terminal (or adding a
test:debug script to your
package.json), we will start a Node process with the
--inspect-brk flag, and then tell it which process to run (in our case, that’s
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --watch
So, what’s going on?
./node_modules/jest/bin/jest.js is where the Jest binary lives that we want to run.
--runInBand flag because Jest runs tests in parallel (which is great for making it a snappy test runner, but bad for our purposes here where we want to be able to step through the code).
--watch because that will make it more dynamic and easier to see how changes affect the code.
That’s it! With that change, we’re able to debug our Jest code just like a normal process! Node will pause automatically on a
debugger statement and the whole thing can be navigated within a Chromium browser.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!