在debugging摩卡testing时,Visual Studio代码中的断点没有命中

我正在使用Mocha(和Chai)进行NodeJS模块的unit testing,并且希望在Visual Studio代码中进行debugging。 我在test子文件夹中有一些TypeScript文件,并test了一些testing。 VScode在out目录中生成.js和.map文件(通过tsc watch模式任务)。 我的tsconfig.json文件包含这些设置:

 { "compilerOptions": { "compileOnSave": true, "module": "commonjs", "target": "es6", "outDir": "out", "removeComments": true, "noImplicitAny": true, "sourceMap": true, "inlineSources": true, "isolatedModules": false, "allowSyntheticDefaultImports": true, "experimentalDecorators": true }, "include": [ "src/**/*", "parser/**/*", "test/**/*" ], "exclude": [ "node_modules", ".vscode-test" ] } 

外面包含3个包含3个子目录。 迄今为止都很好。

我可以使用这个命令运行我的testing:

 mocha --compilers ts:ts-node/register,tsx:ts-node/register 

在vscode之外。 然后,我用--debug-brk开关运行了这段代码,并将vscode连接到它。 这有效,但没有断点。 launch.json中的configuration是:

  { "name": "Attach", "type": "node", "request": "attach", "port": 5858, "address": "localhost", "restart": false, "sourceMaps": true, "outDir": null, "localRoot": "${workspaceRoot}", "remoteRoot": null } 

理想情况下,我想有一个运行configuration,所以我不需要手动运行摩卡。 有了这些设置,我至less可以运行testing:

  { "name": "Mocha", "type": "node", "request": "launch", "cwd": "${workspaceRoot}", "preLaunchTask": "tsc", "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "args": [ "--no-timeouts", "--colors", "${workspaceRoot}/out/test/**/*.js" ], "stopOnEntry": true, "runtimeExecutable": null, "env": { "NODE_ENV": "testing" } "sourceMaps": true } 

但是,仍然没有断点。

要使至less一个scheme有效,需要做什么?

更新 :同时我偶然发现添加debugger;时断点开始工作debugger; 在testing代​​码的某个地方执行命令,并在debugger; 停止后至less设置一个新的断点debugger; 。 之后,这个单个文件中的所有后续断点按预期工作。 看起来几乎像是一个bug。

使用"protocol": "inspector",在启动选项中帮助我继续了一段时间,即使这样做有令人讨厌的副作用,即testing过程在所有事情执行后都没有停止过。 每次运行后我都必须杀掉这个任务。 所以我虽然我会给它另一个尝试find问题,我成功了。 解决方法很简单:将outfiles选项添加到启动选项,否则vscode将在TS源文件夹中查找映射。 通过增加:

  "outFiles": [ "${workspaceRoot}/out/**/*.js" ], 

一切开始很好地工作。 如果vscode会打印一条警告,说明由于缺less设置而无法find源映射,那么这将非常有用。