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
Copy file name to clipboardexpand all lines: packages/react-scripts/template/README.md
+63
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
64
64
-[Disabling jsdom](#disabling-jsdom)
65
65
-[Snapshot Testing](#snapshot-testing)
66
66
-[Editor Integration](#editor-integration)
67
+
-[Debugging Tests](#debugging-tests)
67
68
-[Developing Components in Isolation](#developing-components-in-isolation)
68
69
-[Getting Started with Storybook](#getting-started-with-storybook)
69
70
-[Getting Started with Styleguidist](#getting-started-with-styleguidist)
@@ -1528,6 +1529,68 @@ If you use [Visual Studio Code](https://code.visualstudio.com), there is a [Jest
1528
1529
1529
1530

1530
1531
1532
+
## Debugging Tests
1533
+
1534
+
There are various ways to setup a debugger for your Jest tests. We cover debugging in Chrome and [Visual Studio Code](https://code.visualstudio.com/).
1535
+
1536
+
>Note: debugging tests requires Node 8 or higher.
1537
+
1538
+
### Debugging Tests in Chrome
1539
+
1540
+
Add the following to the `scripts` section in your project's `package.json`
1541
+
```json
1542
+
"scripts": {
1543
+
"test:debug":"react-scripts --inspect-brk test --runInBand --env=jsdom"
1544
+
}
1545
+
```
1546
+
Place `debugger;` statements in any test and run:
1547
+
```bash
1548
+
$ npm run test:debug
1549
+
```
1550
+
1551
+
This will start running your Jest tests, but pause before executing to allow a debugger to attach to the process.
1552
+
1553
+
Open the following in Chrome
1554
+
```
1555
+
about:inspect
1556
+
```
1557
+
1558
+
After opening that link, the Chrome Developer Tools will be displayed. Select `inspect` on your process and a breakpoint will be set at the first line of the react script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack.
1559
+
1560
+
>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.
1561
+
1562
+
### Debugging Tests in Visual Studio Code
1563
+
1564
+
Debugging Jest tests is supported out of the box for [Visual Studio Code](https://code.visualstudio.com).
1565
+
1566
+
Use the following [`launch.json`](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) configuration file:
0 commit comments