Skip to content

Commit d1cae97

Browse files
committed
chore: add debugging configuration for VsCode
1 parent f253686 commit d1cae97

File tree

7 files changed

+89
-4
lines changed

7 files changed

+89
-4
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"llvm-vs-code-extensions.vscode-clangd",
66
"xadillax.gyp",
77
"dbaeumer.vscode-eslint",
8-
"esbenp.prettier-vscode"
8+
"esbenp.prettier-vscode",
9+
"vadimcn.vscode-lldb"
910
]
1011
}

.vscode/launch.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "JS-Attach",
5+
"type": "node",
6+
"request": "attach",
7+
"port": 9229,
8+
"continueOnAttach": true,
9+
"autoAttachChildProcesses": true,
10+
"resolveSourceMapLocations": [
11+
"!**/node_modules/**",
12+
"!**/.vscode/extensions/hbenl.vscode-mocha-test-adapter-*/**"
13+
],
14+
"skipFiles": [
15+
"<node_internals>/**"
16+
],
17+
},
18+
{
19+
"type": "lldb",
20+
"request": "launch",
21+
"name": "Native-Launch",
22+
"preLaunchTask": "clean_build_debug",
23+
"program": "node",
24+
"suppressMultipleSessionWarning": true,
25+
"sourceLanguages": [
26+
"cpp"
27+
],
28+
"args": [
29+
"--inspect-brk=9229",
30+
"--expose-gc",
31+
"-r",
32+
"ts-node/register",
33+
"${workspaceFolder}/test/debug.ts"
34+
],
35+
}
36+
],
37+
"compounds": [
38+
{
39+
"name": "Node-Launch",
40+
"configurations": [
41+
"Native-Launch",
42+
"JS-Attach",
43+
]
44+
}
45+
]
46+
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"mochaExplorer.globImplementation": "vscode",
44
"mochaExplorer.nodeArgv": [
55
"--expose-gc"
6-
]
6+
],
7+
"mochaExplorer.debuggerConfig": "JS-Attach"
78
}

.vscode/tasks.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "clean_build_debug",
6+
"type": "shell",
7+
"command": "pnpm clean.release && pnpm build.debug",
8+
}
9+
]
10+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"scripts": {
8585
"install": "(shx test -f ./script/build.js || run-s build.js) && cross-env npm_config_build_from_source=true aminya-node-gyp-build",
8686
"clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.js.map ./script/*.d.ts ./script/*.tsbuildinfo",
87+
"clean.release": "shx rm -rf ./build/Release",
8788
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp",
8889
"build.library": "tsc -p ./src/tsconfig.json",
8990
"build.script": "tsc -p ./script/tsconfig.json && tsc -p ./script/tsconfig.esm.json",

test/debug.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as zmq from "../src"
2+
3+
import {getGcOrSkipTest} from "./unit/helpers"
4+
5+
async function main() {
6+
const gc = getGcOrSkipTest()
7+
8+
let weakRef: undefined | WeakRef<zmq.Context>
9+
const task = async () => {
10+
const context: zmq.Context | undefined = new zmq.Context()
11+
const dealer = new zmq.Dealer({context, linger: 0})
12+
weakRef = new WeakRef(context)
13+
14+
// dealer.close()
15+
}
16+
17+
await task()
18+
await gc()
19+
20+
console.log(weakRef?.deref())
21+
}
22+
23+
main().catch(err => {
24+
console.error(err)
25+
process.exit(1)
26+
})

test/unit/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ interface GCFunction {
259259
}): void | Promise<void>
260260
}
261261

262-
export function getGcOrSkipTest(test: Mocha.Context) {
262+
export function getGcOrSkipTest(test?: Mocha.Context) {
263263
if (process.env.SKIP_GC_TESTS === "true") {
264-
test.skip()
264+
test?.skip()
265265
}
266266

267267
const gc = global.gc as undefined | GCFunction

0 commit comments

Comments
 (0)