Skip to content

Commit 0ba5cc2

Browse files
authored
[test] Allow debugging with Chrome and VSCode inspector (#29777)
1 parent 3323b23 commit 0ba5cc2

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# However, in order to prevent issues, they are ignored here.
33
.DS_STORE
44
.idea
5-
.vscode
5+
.vscode/*
6+
!.vscode/launch.json
67
*.log
78
*.tsbuildinfo
89
/.eslintcache

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Test Current File",
8+
"program": "test/cli.js",
9+
"args": ["${relativeFile}", "--inspecting"],
10+
"console": "integratedTerminal",
11+
"internalConsoleOptions": "neverOpen",
12+
"disableOptimisticBPs": true
13+
}
14+
]
15+
}

test/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ trade-off, mainly completeness vs. speed.
112112
113113
### React API level
114114
115+
#### Debugging tests
116+
117+
If you want to debug tests with the e.g. Chrome inspector (chrome://inspect) you can run `yarn t <testFilePattern> --debug`.
118+
Note that the test will not get executed until you start code execution in the inspector.
119+
120+
We have a dedicated task to use VSCode's integrated debugger to debug the currently opened test file.
121+
Open the test you want to run and press F5 (launch "Test Current File").
122+
115123
#### Run the core mocha unit/integration test suite.
116124
117125
To run all of the unit and integration tests run `yarn test:unit`

test/cli.js

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ async function run(argv) {
3939
if (argv.bail) {
4040
args.push('--bail');
4141
}
42+
if (argv.debug || argv.inspecting) {
43+
args.push('--timeout 0');
44+
}
4245
if (argv.debug) {
4346
args.push('--inspect-brk');
4447
}
@@ -86,6 +89,16 @@ yargs
8689
description: 'Stop on first error.',
8790
type: 'boolean',
8891
})
92+
.option('debug', {
93+
alias: 'd',
94+
description:
95+
'Allows attaching a debugger and waits for the debugger to start code execution.',
96+
type: 'boolean',
97+
})
98+
.option('inspecting', {
99+
description: 'In case you expect to hit breakpoints that may interrupt a test.',
100+
type: 'boolean',
101+
})
89102
.option('production', {
90103
alias: 'p',
91104
description:

0 commit comments

Comments
 (0)