This repository exposes an issue with using vscode-js-debug
in the cases where program
is a wrapper used to determine an actual file.
For purposes of the example, the compiled files and sourcemaps are available in ./dist
npm install
Given the configuration
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"program": "${workspaceFolder}/bin/mocha-current-file",
"args": [
"${file}"
],
"outFiles": [
"${workspaceFolder}/dist"
],
"sourceMaps": true,
}
The file ./bin/mocha-current-file.js does the following:
- consumes the
${file}
argument, which is the currently focused file in the vscode editor. In this example, it issrc/index.unit.ts
- determines the name and location of the compiled typescript file, in this case,
dist/index.unit.js
- Shows an (unfollowed) example of a setup where there might be complicated "before all test" setup, e.g. for cleanly creating and tearing down databases.
- invokes mocha through
require('mocha/lib/cli').main(['dist/index.unit.js])
You can substitute your favorite test framework, this also happens with Jest and AVA.
// settings.json
{
"debug.javascript.usePreview": false,
}
Note how we are currently stopped on the breakpoint in the source file.
// settings.json
{
"debug.javascript.usePreview": false,
}
Note how we are currently stopped on the debugger;
line in the compiled distfile ./dist/index.unit.js
Traces are committed to ./tracefile.json