Skip to content
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

Enable CLI debugger with Jest #691

Closed
amandapouget opened this issue Sep 21, 2016 · 7 comments
Closed

Enable CLI debugger with Jest #691

amandapouget opened this issue Sep 21, 2016 · 7 comments

Comments

@amandapouget
Copy link

amandapouget commented Sep 21, 2016

Would be really great if there was a 'test debug' command that enabled a command-line debugger. There is an issue open to make a debugger work for the browser but I think a command-line debugger would be more useful.

Or, at least, documentation on the recommended command and/or tool to use alongside create-react-app to get a CLI debugger running for existing tests.

@gaearon
Copy link
Contributor

gaearon commented Sep 21, 2016

I think most people would want to use Chrome for debugging. Is there some particular reason why you prefer a CLI debugging interface? Does one exist for Node? (I’ve never used one to be honest.)

@amandapouget
Copy link
Author

I’m really surprised that most people would prefer Chrome debugging, in that walking through tests with a debugger is a very standard and popular thing with, say, Ruby (pry). In a previous project, we used this command: "test_debug": "node debug ./node_modules/jasmine/bin/jasmine.js”.

In short, if a test fails, it’s easier to just throw in a debugger and use a different test command than it is to bother going and opening and browser and all of that. Chrome’s tools are great, but honestly, if you’re debugging regular domain models and not the react components themselves, there is no reason to get a browser involved when you just want to break at a certain line of a test. I usually have my CLI and my editor arranged on the screen such that switching out of CLI because I happen to be running for a debug is just a pain… I’d rather throw in a bunch of console.logs to get around the issue than open up a browser to pry apart one test.

It would seem that adding a CLI debugger command would be a really simple task here, provided that Jest allows you to debug the same way Jasmine does.

On Sep 21, 2016, at 9:37 AM, Dan Abramov notifications@github.com wrote:

I think most people would want to use Chrome for debugging. Is there some particular reason why you prefer a CLI debugging interface? Does one exist for Node? (I’ve never used one to be honest.)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #691 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AMQpjL8gBsq947pwCusUaPdjTLr75vGcks5qsTMigaJpZM4KCzkr.

@amandapouget
Copy link
Author

Another primary limitation of "Chrome-only" debugger tools is, how do you debug server-side code? You can do that with a CLI debugger but not Chrome.

@amandapouget
Copy link
Author

You can see others are monkey-patching Jest to accomplish this:
http://stackoverflow.com/questions/25142173/debugging-jest-test-cases-using-node-inspector

@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2016

Another primary limitation of "Chrome-only" debugger tools is, how do you debug server-side code? You can do that with a CLI debugger but not Chrome.

To clarify, debugging Node (potentially server-side) code is exactly what I meant by “Chrome debugging”. This is a very recent officially supported feature in Node, so it’s not documented well yet.

This is what I’m referring to:

https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

http://facebook.github.io/jest/docs/troubleshooting.html#tests-are-failing-and-you-don-t-know-why

bmihelac added a commit to bmihelac/create-react-app-test-debug-example that referenced this issue Jun 6, 2017
See facebook/create-react-app#691

Run:

```
npm run test-debug
```

Or

```
CI=1 node debug node_modules/react-scripts/scripts/test.js --runInBand --env=jsdom src/App.test.js
```
@bmihelac
Copy link

bmihelac commented Jun 6, 2017

It looks like devtools debugging currently does not work (#2041) CLI debugger looks like only way to debug or inspect tests at the moment.

Here is an example that would run debugger on single test:

CI=1 node debug node_modules/react-scripts/scripts/test.js --runInBand --env=jsdom src/App.test.js

CI env option is to disable watch mode, --runInBand to run tests serially

And screenshot:

691

This was made on fresh create-react-app with adding debugger statement:

bmihelac/create-react-app-test-debug-example@d171143

@gaearon
Copy link
Contributor

gaearon commented Jan 8, 2018

I'll close this we've documented the Chrome debugger (https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#debugging-tests-in-chrome).

Hope the above helps for those who want a CLI debugger.

@gaearon gaearon closed this as completed Jan 8, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants