Skip to content

Commit 80f29f5

Browse files
authored
feat: Added test:debug script (#1628)
Added a `test:debug` npm script. resolves #1627
1 parent 61d1a53 commit 80f29f5

3 files changed

Lines changed: 41 additions & 8 deletions

File tree

.vscode/settings.json

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
}
99
],
1010
"editor.defaultFormatter": "esbenp.prettier-vscode",
11-
"stylelint.validate": [
12-
"css",
13-
"html",
14-
"sass",
15-
"scss"
16-
],
11+
"stylelint.validate": ["css", "html", "sass", "scss"],
1712
"launch": {
1813
"version": "0.2.0",
1914
"configurations": [
@@ -24,8 +19,37 @@
2419
"url": "http://localhost:4000",
2520
"webRoot": "${workspaceFolder}",
2621
"userDataDir": "${workspaceFolder}/.vscode/chrome-debug-profile"
22+
},
23+
{
24+
"type": "node",
25+
"request": "attach",
26+
"name": "Attach to Node Process",
27+
"port": 9229
28+
},
29+
{
30+
"name": "Debug Jest Tests",
31+
"type": "node",
32+
"request": "launch",
33+
"runtimeArgs": [
34+
"--inspect-brk",
35+
"${workspaceRoot}/node_modules/.bin/jest",
36+
"--config",
37+
"jest.config.unit.cjs",
38+
"--runInBand",
39+
"--watch",
40+
"${input:pickFile}"
41+
],
42+
"console": "integratedTerminal",
43+
"internalConsoleOptions": "neverOpen"
2744
}
2845
],
29-
"compounds": []
46+
"compounds": [],
47+
"inputs": [
48+
{
49+
"id": "pickFile",
50+
"type": "promptString",
51+
"description": "Test pattern or filename"
52+
}
53+
]
3054
}
31-
}
55+
}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ Note that log messages from other sources such as react prop types will still be
9494

9595
If you want to collect coverage locally, run `npm test -- --coverage`
9696

97+
### Debugging Unit Tests
98+
Unit tests can be debugged by running jest with the `--inspect-brk` flag and attaching to the node process in vscode's debugger. There are 2 launch configs that make this easier:
99+
100+
- Debug Jest Tests - This will prompt you for a test name or pattern and will then run tests in watch mode with an attached debugger.
101+
- Attach to Node Process - This will attempt to attach to an existing node process running with `--inspect-brk`. There is an npm script `test:debug` that can start the process for you. By default, it will run with the same configuration as `npm test`, but you can supply additional parameters to narrow the scope of tests being run.
102+
103+
e.g. `npm run test:debug ThemeUtils` would only run modules with "ThemeUtils" in the name.
104+
97105
## E2E Tests
98106

99107
We use [Playwright](https://playwright.dev/) for end-to-end tests. We test against Chrome, Firefox, and Webkit (Safari). Snapshots from E2E tests are only run against Linux so they can be validated in CI.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"start:embed-grid": "lerna run start --scope=@deephaven/embed-grid --stream",
4242
"pretest": "npm run build:necessary",
4343
"test": "jest --watch --changedSince origin/main",
44+
"test:debug": "node --inspect-brk node_modules/.bin/jest --config jest.config.unit.cjs --runInBand --watch",
4445
"pretest:unit": "npm run pretest",
4546
"test:unit": "jest --config jest.config.unit.cjs",
4647
"test:lint": "jest --config jest.config.lint.cjs",

0 commit comments

Comments
 (0)