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

Docs: How to Debug Unit Tests #2992

Merged
merged 4 commits into from
Nov 14, 2017
Merged

Docs: How to Debug Unit Tests #2992

merged 4 commits into from
Nov 14, 2017

Conversation

MattMorgis
Copy link
Contributor

This updates the docs to include a “Debugging Tests” section.

I included how to use debug Jest tests with Chrome/Node Inspector and the new —inspect flag.

I also included the configuration file for debugging tests directly in VS Code.

I think this mostly closes #594. I know @prigara wanted to additionally add a section about debugging Webstorm too, which would really finish this off!

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!


To attach the `node-inspector` debugger, run:
```
node-inspector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit out of touch but I had an impression that node-inspector is no longer necessary, and Node integration just works out of the box with Chrome. Is that wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I had no idea, just gave it a shot and you are correct.

Updating this!

"name": "Debug CRA Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot/node_modules/.bin/react-scripts",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing } after workspaceRoot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MattMorgis
Copy link
Contributor Author

Updated to reflect review comments.

Just tested again in Chrome and VS Code and both are working well.

Node: v8.4
React Scripts: 1.0.12
VS Code: 1.15.1


Windows
```bash
node node_modules/bin/react-scripts --inspect-brk test --runInBand --testPathIgnorePatterns=ui-tests/* --env=jsdom
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ui-tests/*? Seems like that shouldn't be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, good catch. Fixed.

Windows
```bash
node node_modules/bin/react-scripts --inspect-brk test --runInBand --testPathIgnorePatterns=ui-tests/* --env=jsdom
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a general note: instead of a Terminal command, can we suggest adding

  "test:debug": "react-scripts --inspect-brk test --runInBand --env=jsdom"

to scripts in package.json and then ask you to run npm run test:debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is much cleaner. Updated!

@DianaSuvorova
Copy link

DianaSuvorova commented Sep 5, 2017

@MattMorgis First of all thank you for the write up. Unfortunately the set up doesn't work for me. I am able to open inspector and browse files after running npm run test:debug. But it would never stop on breakpoint I set up in the inspector or a debugger. I can push it up to a branch if you would want to take a look. Thanks!

Update: The not stopping on breakpoint seems to be some node issue. Switching to node v8 (v as in version) fixed it. Now the the question is what about sourceMaps? Is there a way to link source maps?

@Timer
Copy link
Contributor

Timer commented Nov 14, 2017

This is great! Sorry for letting it slip through the cracks.

@Timer Timer added this to the 1.0.17 milestone Nov 14, 2017
@Timer Timer merged commit b555192 into facebook:master Nov 14, 2017
placenamehere pushed a commit to automatastudios/create-react-app that referenced this pull request Nov 30, 2017
* docs: adding section about debugging tests

* docs: removing node-inspector references

* docs: replacing terminal command with npm script

* Update README.md
@gaearon gaearon mentioned this pull request Jan 15, 2018
Pavek pushed a commit to Pavek/create-react-app that referenced this pull request Jul 10, 2018
* docs: adding section about debugging tests

* docs: removing node-inspector references

* docs: replacing terminal command with npm script

* Update README.md
zmitry pushed a commit to zmitry/create-react-app that referenced this pull request Aug 14, 2018
* docs: adding section about debugging tests

* docs: removing node-inspector references

* docs: replacing terminal command with npm script

* Update README.md
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to debug unit tests
6 participants