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

Updating Troubleshooting.md to include --inspect #4312

Merged
merged 2 commits into from
Aug 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 78 additions & 4 deletions docs/en/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ Uh oh, something went wrong? Use this guide to resolve issues with Jest.

Try using the debugging support built into Node.

> Note: Debugging support with Jest only supports `node debug`; it does yet support `node inspect` due to an upstream issue in [nodejs/node#7583](https://github.com/nodejs/node/issues/7593). Until the upstream issue is resolved, debugging with Node is not available when using Node v8.x. For more details, see [facebook/jest#1652](https://github.com/facebook/jest/issues/1652).

Place a `debugger;` statement in any of your tests, and then, in your project's directory, run:

```
node --debug-brk ./node_modules/.bin/jest --runInBand [any other arguments here]
node --inspect-brk node_modules/.bin/jest --runInBand [any other arguments here]
or on Windows
node --debug-brk ./node_modules/jest/bin/jest.js --runInBand [any other arguments here]
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand [any other arguments here]
```

This will run Jest in a Node process that an external debugger can connect to. Note that the process
Expand All @@ -43,6 +41,82 @@ This will output a link that you can open in Chrome. After opening that link, th

> Note: the `--runInBand` cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.

### Debuggin in VS Code

There are multiple ways to debug Jest tests with [Visual Studio Code's](https://code.visualstudio.com) built in [debugger](https://code.visualstudio.com/docs/nodejs/nodejs-debugging).

To attach the built-in debugger, run your tests as aforementioned:
```
node --inspect-brk node_modules/.bin/jest --runInBand [any other arguments here]
or on Windows
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand [any other arguments here]
```

Then attach VS Code's debugger using the following `launch.json` config:
```json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
},
]
}
```

To automatically launch and attach to a process running your tests, use the following configuration:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
```

If you are using Facebook's [`create-react-app`](https://github.com/facebookincubator/create-react-app), you can debug your Jest tests with the following configuration:

```json
{
"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"
}
]
}
```

More information on Node debugging can be found [here](https://nodejs.org/api/debugger.html).

### Caching Issues
Expand Down