-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to debug unit tests #594
Comments
I can work on this. |
👍 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 😅 |
I mean But that would be a very cool feature. I've been looking for a good debugging tool for tests all around. |
@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:
|
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+. |
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: 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 |
You should probably run Jest with |
Trying to run it too, but no luck
and when continue it ignores |
|
can I ask to take a look? |
yikes. surprised this hasn't
and in fact it honored my |
can anyone furnish a successful workflow debugging via react-scripts with source maps? |
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! |
Awesome |
any news on this issue?? testing with cra is quite disappointing |
If there were news at the time, they would be on the issue. This is generally true in any open source project. Nobody wants to withhold good news on an open issue if there any. :-)
You are not "adding heat" with a comment that does nothing to advance the conversation. Comments like this just cause extra stress for maintainers for whom this is an additional notification that carries no information. Let's all try to keep the issue tracker signal rather than noise by only posting when we have important information to share. You can use the GitHub voting feature to vote for issues that affect you. If you want to help you are welcome. Last time I checked, debugging tests was blocked by this Jest issue (already linked from this thread earlier): jestjs/jest#1652. The Jest issue was blocked by a Node issue (as you can see by reading that thread): nodejs/node#7593. And as you can see somebody finally solved it in Node 8.4 just about now: jestjs/jest#1652 (comment). So if you'd like to help, please test whether that suggestion works in Node 8.4, and if it does, please send a PR documenting it. Thanks! |
Try this with Node 8.4:
We'll probably add some sweeter alternative way to run this but please check if this works. |
The following should also work (?): ./node_modules/.bin/react-scripts --inspect --inspect-brk test --env=jsdom --runInBand #2041 should turn making |
thx guys.
^ will not work because
^ will not work because of the way a 🚨 hack 🚨 is to modify from: case 'test': {
const result = spawn.sync(
'node',
[require.resolve('../scripts/' + script)].concat(args),
{ stdio: 'inherit' }
); to: case 'test': {
const result = spawn.sync(
'node',
['--inspect', '--inspect-brk', require.resolve('../scripts/' + script)].concat(args),
{ stdio: 'inherit' }
); now, you can run:
|
PS, i dont recommend the hack--i recommend someone pick up #2041, but it's a useful unblocker! |
Did you test It should work, but I can't test it right now. This feature is only available on v1.0.11+. |
i did not! i tested on i see what you're up to now. nice! |
Optimally, I'd love to make Given current: Something like filtering |
Or maybe it'd be better to only automatically append Everything works fine now as-is and we could document it as such, but maybe we can make it friendlier! |
After some experimentation on Friday and again this morning, I came up with this VS Code This works with CRA/ Node: Update: works with {
"version": "0.2.0",
"configurations": [
{
"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"runtimeArgs": [
"--inspect-brk",
"test"
],
"args": [
"--runInBand",
"--no-cache",
"--env=jsdom"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
} I'd be happy to send in PR with the updated docs on this? |
I've sent a PR to Jest adding a section about debugging Jest tests in WebStorm, similar to what @MattMorgis did for VS Code. |
@prigara Sounds good to me — I'm on board to help with documenting the VS Code stuff! |
@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 |
@rsmolkin Glad it worked! I get that same |
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. |
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. |
@TheTFo I might be able to help! Can you setup a small sample project reproducing it? Also, where are you seeing the |
I'll try to put together a repro tomorrow! Thanks!
I was seeing the 7.4.0, (7.9.0 after I upgraded today) in the Help -> About
menu.
…On Sat, Oct 7, 2017, 9:18 PM Matt Morgis ***@***.***> wrote:
@TheTFo <https://github.com/thetfo> I might be able to help! Can you
setup a small sample project reproducing it? Also, where are you seeing the
7.4.0 in VS Code?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#594 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAgWoKDZ6mcayuM_9fTwAKMVOj9u1TEvks5sqCLWgaJpZM4J1890>
.
|
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! |
@MattMorgis Did you have a chance to dig into my project? Thanks again! |
Thank you! So happy to have this fixed. I really appreciate the updated docs for vscode and IntelliJ! |
For whom it may concern: To sum up my local working setup with docker and Jetbrains Editor:
|
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.
The text was updated successfully, but these errors were encountered: