Document how to debug unit tests
We should provide/document a way to do this: https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27. Support for this landed in Node 6.3.0.
I can work on this.
:+1:
I'm not sure if there's anything we need to expose here. I wonder how to pass flags to node when using npm scripts.
@gaeron It's not pretty. @kentcdodds did something similar not so long ago.
It's actually not terrible. The latest node 6 has --inspect and jest has documentation on how to debug with a browser.
Haha, just noticed Dan already mentioned it's available in node 6 :sweat_smile:
I mean node --inspect ./node_modules/.bin/jest is less ideal than jest -- --inspect or something similar 😄.
And you need to test if node version is compatible, indeed.
But that would be a very cool feature. I've been looking for a good debugging tool for tests all around.
What really works for me, at the moment, is WebStorm/IntelliJ + mocha (out-of-the-box support for a node script located in /node_modules/_mocha without sourcemap support).
Native debugging in node is a big improvement.
jest has documentation on how to debug with a browser
@kentcdodds I can't find the documentation on their site. Do you know where it is? It was announced in this June blog post, but the link doesn't go anywhere anymore
Huh... That's weird... I can't find it anymore either. I wonder if @cpojer or @dmitriiabramov can explain why.
If I recall correctly, it was something like:
node --inspect --debug-brk ./node_modules/jest-cli --runInBand
Yeah we removed the outdated docs for Jest that relied on node-inspector or other third party tools. Would appreciate a PR to Jest that adds docs on how to do this with node 6.3+.
I mean node --inspect ./node_modules/.bin/jest is less ideal than jest -- --inspect or something similar 😄. And you need to test if node version is compatible, indeed.
But we can do exactly that automatically from scripts/test.js. So it could be a simple --debug flag on react-scripts side.
So the idea is:
From the user side, let them use something like react-scripts test --debug to trigger testing with debugging in browser.
Add functionality to scripts/test to call the (potentially ugly) command node --inspect ./node_modules/.bin/jest ... when the --debug flag is passed?
I starting looking at this, and one problem I'm running into is that when I open the browser debugger, I can only seem to step through the code of jest itself, rather than my tests. Anyone experienced that before?
You should probably run Jest with -i because otherwise Jest will run tests in worker processes.
Trying to run it too, but no luck
node --inspect --debug-brk ./node_modules/jest-cli/bin/jest.js -i --runInBand ./path-to-test.js and getting debugger stopped at jest-cli code here
> 'use strict';
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'test';
}
require('../build/cli').run();
});
and when continue it ignores debugger statement inside my test
node --inspect is still ignoring debugger statements, so I think we're going to have to wait until this Jest issue is resolved
can I ask to take a look? http://stackoverflow.com/questions/39798495/how-to-debug-jest-unit-tests-on-create-react-app
yikes. surprised this hasn't ~~come up before~~ had more heat applied to it. i see that react-scripts creates a jest config in mem. i wrote that config to disk, updated the targetEnvironment to jsdom instead of node, then ran:
node --debug-brk ./node_modules/.bin/jest --config jest-config.json --runInBand -i --no-cache src/__test__/<my-file>.test.js
and in fact it honored my debugger but it was super mangled (e.g. no source maps) :/
can anyone furnish a successful workflow debugging via react-scripts with source maps?
surprised this hasn't
come up beforehad more heat applied to it.
You can apply some heat by submitting a PR. 😉
i would love to do that once i get it to work! :)
got it, PR comin' in hot!