视觉工作室代码debugging摩卡忽略断点

我正在尝试在Visual Studio代码中debugging摩卡unit testing。 我跟着这个问题 ,得到这个运行configuration:

{ "name": "Run mocha", "type": "node", "program": "/usr/bin/mocha", "stopOnEntry": false, "args": ["testUtils.js"], "cwd": "${workspaceRoot}", "runtimeExecutable": null, "env": { "NODE_ENV": "development"} }, 

有用。 但它并不止于断点! 如果我用正常的启动configuration运行该文件,则不会忽略断点。

任何想法可能是什么原因呢?

这对我_mocha ,你需要指向_mocha 。 只使用mocha不允许附加断点。

  { "name": "Debug mocha", "type": "node", "request": "launch", "runtimeArgs": ["C:\\Users\\CS\\AppData\\Roaming\\npm\\node_modules\\mocha\\bin\\_mocha"], "program": "${workspaceRoot}\\test.js", "stopOnEntry": false, "args": [ ], "cwd": "${workspaceRoot}", "runtimeExecutable": null, "env": { "NODE_ENV": "development" } } 

如果你包含端口和“–debug-brk”参数,你应该可以debugging摩卡unit testing。 我在我的launch.json文件中有以下设置。 我还包括了“ – recursion”的参数,所以摩卡会在子文件夹中运行所有的testing。 使用这个configuration文件,我只需将我的VS Codedebugging器设置为使用“debugging摩卡testing”configuration,我就可以在我的任何testing文件中打断点。

 { // Use IntelliSense to learn about possible Node.js debug attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceRoot}/server.js", "cwd": "${workspaceRoot}" }, { "type": "node", "request": "attach", "name": "Attach to Process", "port": 5858 }, { "type": "node", "request": "launch", "name": "Debug Mocha Test", "port": 5858, "runtimeArgs": ["${workspaceRoot}/node_modules/mocha/bin/mocha"], "cwd": "${workspaceRoot}", "args": ["--recursive", "--debug-brk"] } ] } 

您可以通过运行mocha --debug-brk来validation摩卡将用于debugging的端口