I have some "node 18 test runner" tests written. I can run them with this command:
node --loader tsx --test tests/**/*.ts
I want to be able to debug the tests in vscode, so I figured I should have a launch.json
configuration entry for that. But how do I do that?
This is what I tried:
{
"version": "0.2.0",
"configurations": [
{
"name": "test",
"type": "node",
"request": "launch",
"args": [
"--loader",
"tsx",
"--test",
"--test-reporter=spec",
"tests/**/*.ts"
],
"console": "integratedTerminal",
"sourceMaps": true,
"internalConsoleOptions": "neverOpen",
},
]
}
When I run this configuration, this is the executed command:
❯ node --loader tsx --test tests/**/*.ts cd /home/birger/someproject ; /usr/bin/env 'NODE_OPTIONS=--require /usr/share/code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js --ins
pect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.165926-f285dca5-96.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/birger/.nvm/versions/node/v18.15.0/bin/node","o
nlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-4ea344155215e4e5"}' /home/birger/.nvm/versions/node/v18.15.0/bin/node --loader tsx --test --test-reporter=spec tests/**/*
.ts
This is the output:
Could not find '/home/birger/someproject/cd'
Debugger attached.
Could not find '/home/birger/someproject/tests/**/*.ts'
Waiting for the debugger to disconnect...
The command ls /home/birger/someproject/tests/
yields a list of 4 .ts files.
How can I write a vscode launch.json configuration to debug the node 18 test runner tests?
2
Answers
Node version: v19.9.0
Project folder structure:
tests/modules/a.test.ts
:package.json
:.vscode/launch.json
:Click the "RUN AND DEBUG" arrow button, result: