You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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?
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
I've sent a PR to Jest adding a section about debugging Jest tests in WebStorm, similar to what @mattmorgis did for VS Code.
I think, we can add a new section Debugging Tests right after Running Tests that will cover debugging tests in Chrome with --inspect --inspect-brk --, debugging in VS Code and in WebStorm. What do you think?
@mattmorgis I tried 3 other configurations that I found online, none worked. Yours from 10 days ago above worked! But oddly, when it starts, I still get a deprecation warning about
(node:32460) [DEP0062] DeprecationWarning: node --inspect --debug-brk is deprecated. Please use node --inspect-brk instead.
Which is strange, cause in the config the runtimeArgs say --inspect-brk. So I'm just curious why this thing may still be complaining. But the main thing is it works. So thanks!
@rsmolkin Glad it worked! I get that same DeprecationWarning — I think it's specific to VS Code's debugger. It does print out that it's using the Inspector protocol in the debug console, however. Running in Chrome doesn't output anything. 🤷♂️
I'm using node 8.4.0 with @mattmorgis launch config above in VSCode. The breakpoints hit fine in my tests, but when I dive into the code being tested, it seems to break in odd places, like the source mapping isn't working. Are there certain configurations that need to be in place for source maps to work?
FWIW, I'm a bit of newb, node -v shows 8.4.0, vscode help is showing version 7.4.0, but I don't think that's what executes the tests. Coul dbe wrong though.
Thanks!
EDIT: I forgot to mention, I'm using flow. Also, it looks like some files this is fine for. Debugging redux thunks (nested functions and such) appears to be where the problem is.
Activity
wdhorton commentedon Sep 6, 2016
I can work on this.
gaearon commentedon Sep 6, 2016
👍
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.
geowarin commentedon Sep 6, 2016
@Gaeron It's not pretty. @kentcdodds did something similar not so long ago.
kentcdodds commentedon Sep 6, 2016
It's actually not terrible. The latest node 6 has --inspect and jest has documentation on how to debug with a browser.
kentcdodds commentedon Sep 6, 2016
Haha, just noticed Dan already mentioned it's available in node 6 😅
geowarin commentedon Sep 6, 2016
I mean
node --inspect ./node_modules/.bin/jestis less ideal thanjest -- --inspector 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/_mochawithout sourcemap support).Native debugging in node is a big improvement.
wdhorton commentedon Sep 7, 2016
@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
kentcdodds commentedon Sep 7, 2016
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:
cpojer commentedon Sep 7, 2016
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+.
gaearon commentedon Sep 7, 2016
But we can do exactly that automatically from scripts/test.js. So it could be a simple --debug flag on react-scripts side.
wdhorton commentedon Sep 7, 2016
So the idea is:
From the user side, let them use something like
react-scripts test --debugto trigger testing with debugging in browser.Add functionality to
scripts/testto call the (potentially ugly) commandnode --inspect ./node_modules/.bin/jest ...when the--debugflag 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
jestitself, rather than my tests. Anyone experienced that before?cpojer commentedon Sep 7, 2016
You should probably run Jest with
-ibecause otherwise Jest will run tests in worker processes.maximderbin commentedon Sep 8, 2016
Trying to run it too, but no luck
node --inspect --debug-brk ./node_modules/jest-cli/bin/jest.js -i --runInBand ./path-to-test.jsand getting debugger stopped atjest-clicode hereand when continue it ignores
debuggerstatement inside my test29 remaining items
prigara commentedon Aug 22, 2017
I've sent a PR to Jest adding a section about debugging Jest tests in WebStorm, similar to what @mattmorgis did for VS Code.
I think, we can add a new section
Debugging Testsright afterRunning Teststhat will cover debugging tests in Chrome with--inspect --inspect-brk --, debugging in VS Code and in WebStorm. What do you think?mattmorgis commentedon Aug 22, 2017
@prigara Sounds good to me — I'm on board to help with documenting the VS Code stuff!
mattmorgis commentedon Aug 22, 2017
@prigara Got the party started with this PR.
rsmolkin commentedon Aug 31, 2017
@mattmorgis I tried 3 other configurations that I found online, none worked. Yours from 10 days ago above worked! But oddly, when it starts, I still get a deprecation warning about
(node:32460) [DEP0062] DeprecationWarning:
node --inspect --debug-brkis deprecated. Please usenode --inspect-brkinstead.Which is strange, cause in the config the runtimeArgs say --inspect-brk. So I'm just curious why this thing may still be complaining. But the main thing is it works. So thanks!
mattmorgis commentedon Sep 1, 2017
@rsmolkin Glad it worked! I get that same
DeprecationWarning— I think it's specific to VS Code's debugger. It does print out that it's using the Inspector protocol in the debug console, however. Running in Chrome doesn't output anything. 🤷♂️kriim commentedon Sep 17, 2017
VS Code doesn't hit breakpoints using this setup unless using Node 8.4.0+ (jestjs/jest#1652). I tried with 8.0.0 and 8.5.0, where only 8.5.0 worked.
That might be worth mentioning.
TheTFo commentedon Oct 7, 2017
Hi all,
I'm using node 8.4.0 with @mattmorgis launch config above in VSCode. The breakpoints hit fine in my tests, but when I dive into the code being tested, it seems to break in odd places, like the source mapping isn't working. Are there certain configurations that need to be in place for source maps to work?
FWIW, I'm a bit of newb, node -v shows 8.4.0, vscode help is showing version 7.4.0, but I don't think that's what executes the tests. Coul dbe wrong though.
Thanks!
EDIT: I forgot to mention, I'm using flow. Also, it looks like some files this is fine for. Debugging redux thunks (nested functions and such) appears to be where the problem is.
mattmorgis commentedon Oct 8, 2017
@TheTFo I might be able to help! Can you setup a small sample project reproducing it? Also, where are you seeing the
7.4.0in VS Code?TheTFo commentedon Oct 8, 2017
TheTFo commentedon Oct 8, 2017
Here's a reproduction, https://github.com/TheTFo/cria/tree/jest-debug
Please see /src/actions/todoActions.js, line 15, launch Jest debugging from VSCode.
I appreciate the time!
TheTFo commentedon Oct 16, 2017
@mattmorgis Did you have a chance to dig into my project?
Thanks again!
avantgardnerio commentedon Nov 14, 2017
Thank you! So happy to have this fixed. I really appreciate the updated docs for vscode and IntelliJ!
valoricDe commentedon Nov 14, 2017
For whom it may concern: To sum up my local working setup with docker and Jetbrains Editor:
docker run -p 9229:9229 -volume ... node:8.9.0 ...package.json:"test-debug": "react-scripts --inspect-brk=0.0.0.0:9229 test --env=jsdom --runInBand -i"PhpStorm:Edit Configurations: + Chromium Remote: Host: MYDOCKERIP Port: 9229