Skip to content

Commit 4345319

Browse files
authored
update debugging, improve docu based on feedback (#113)
updates debugging approach, updates docu
1 parent 9bd177f commit 4345319

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

.vimspector.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"adapter": "js-debug",
55
"configuration": {
66
"request": "attach",
7-
"outDir": "${workspaceRoot}/dist/**.js",
8-
"program": "${workspaceRoot}/src/index.ts",
9-
"cwd": "${workspaceRoot}",
10-
"stopOnEntry": false
7+
"outDir": "${workspaceRoot}/dist",
8+
"skipFiles": ["<node_internals>/**"],
9+
"cwd": "${workspaceRoot}"
1110
},
1211
"breakpoints": {
1312
"exception": {

.vscode/launch.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
52
"version": "0.2.0",
63
"configurations": [
74
{
5+
"name": "debug",
86
"type": "node",
9-
"request": "launch",
10-
"name": "Launch Program",
7+
"request": "attach",
118
"skipFiles": ["<node_internals>/**"],
12-
"program": "${workspaceFolder}/dist/src/index.js",
13-
"preLaunchTask": "tsc: build - tsconfig.json",
149
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
1510
}
1611
]

README.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ attribute.
9494
rebuilds the project. It does also watch all changes made to the built project
9595
and restarts the code whenever changes are detected. This enables a quick
9696
feedback loop.
97+
- `yarn debug` -> Starts the app in debugging mode. Waits for a debugger to
98+
attach. See Debugging below for more info.
99+
- If you want to restart the debugging process every time you change the code,
100+
you can use something like `nodemon --watch src --watch test --ext ts,json
101+
--exec 'yarn debug'` or when debugging tests with `nodemon --watch src --watch
102+
test --ext ts,json --exec 'yarn debug:test'`
103+
- `yarn debug:test` -> Starts the test run in debugging mode. Waits for a
104+
debugger to attach. See Debugging below for more info.
97105
- `yarn format` -> Formats the code using prettier.
98106
- `yarn format:check` -> Checks for formatting errors using prettier. This is
99107
typically only invoked by the CI/CD pipeline.
@@ -120,39 +128,35 @@ DAP compliant debugger
120128

121129
### Debugging Code
122130

123-
#### Vim
131+
There are somewhat "different" ways of starting the debugger. Once is by
132+
starting the app and waiting for a debugger to connect and the other one is
133+
starting the app initiated by the debugger. I made the experience that the
134+
former works on any given code base, no matter the amount of transipilation or
135+
bundling steps and custom steups while the latter does fail in extremely
136+
customized scenarios. Therefore here only the first one is covered with
137+
examples.
124138

125-
- Start the node process with inspect-brk `yarn bundle && node
126-
--enable-source-maps --inspect-brk ./dist/src/index.js` in one terminal.
127-
- Open src/index.ts `vim ./src/index.ts` in another terminal.
128-
- Set breakpoint in line 6 (F9 is the default mapping)
129-
- Start vimspector by pressing F5
139+
#### Vim or Vscode
140+
141+
- Run `yarn debug` in another terminal
142+
- Open src/index.ts `vim ./src/index.ts` (or code ./src/index.ts) in another terminal.
143+
- Set breakpoint somewhere in the file at the console log (F9 is the default mapping).
144+
- Start by pressing F5
130145
- Press F5 again, should see the console.log output
131146
- Done🎉
132147

133-
#### Vscode
134-
135-
- Open code, set a breakpoint in src/index.ts and just start debugging with F5.
136-
137148
### Debugging Tests
138149

139-
#### Vim
150+
#### Vim or Vscode
140151

141-
- Start the node process with inspect-brk `node --enable-source-maps
142-
--inspect-brk --no-lazy ./node_modules/.bin/jest --runInBand .` in one
143-
terminal.
152+
- Run `yarn debug:test` in another terminal
144153
- Open src/index.ts `vim ./src/hello.test.ts` in another terminal.
145-
- Set breakpoint in line 8 (F9 is the default mapping)
146-
- Start vimspector by pressing F5
147-
- You should see the first console log already "testing returnHelloWorld()"
148-
- Press F5 again, should see the second console.log "Done"
154+
- Set breakpoint in the line of the console log in the test file.
155+
- Start by pressing F5 (then skip the jest internal file once with F5)
156+
- Check the terminal where you ran `yarn debug:test`, it should not display the console log yet.
157+
- Press F5 again, should see the console.log output there now.
149158
- Done🎉
150159

151-
#### Vscode
152-
153-
- Open code and set a breakpoint in /src/hello.test.ts.
154-
- Go to the package.json in the 'scripts' sections, click on 'debug' and select 'test'.
155-
156160
## Linting
157161

158162
This repo has [eslint](https://eslint.org/) and

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"compile": "tsc",
3333
"compile:watch": "tsc -w",
3434
"dev": "nodemon --watch src --watch test --ext ts,json --exec 'yarn bundle && yarn start'",
35+
"debug": "yarn bundle && node --enable-source-maps --inspect-brk ./dist/index.js",
36+
"debug:test": "node --inspect-brk ./node_modules/.bin/jest --runInBand .",
3537
"format": "prettier . --write",
3638
"format:check": "prettier . --check",
3739
"lint": "eslint . --fix",

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
const main = () => {
66
console.log("hello Node.js and Typescript world :]");
7+
console.log("live reloading");
8+
console.log("live reloading2");
79
};
810

911
// This was just here to force a linting error for now to demonstrate/test the
10-
// eslint pipeline. You can uncomment this and run "yarn check-lint" to test the
12+
// eslint pipeline. You can uncomment this and run "yarn lint:check" to test the
1113
// linting.
1214
// const x: number[] = [1, 2];
1315
// const y: Array<number> = [3, 4];
14-
15-
// This was just here to force a linting error for now to demonstrate/test the
16-
// eslint pipeline. You can uncomment this and run "yarn check-lint" to test the
17-
// linting.
1816
// if (x == y) {
1917
// console.log("equal!");
2018
// }

0 commit comments

Comments
 (0)