2016-05-23 98 views
2

我想在Visual Studio代码中调试摩卡单元测试。我跟着这个question得到这个运行配置:视觉工作室代码调试摩卡忽略断点

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

它的工作原理。但它并不止于断点!如果我使用正常的启动配置运行该文件,则不会忽略断点。

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

回答

3

这适用于我,你需要指向_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" 
     } 
    } 
+0

哦用于调试,我应该检查我自己。我虽然/ usr/bin/mocha会很好,并没有考虑过三次。 – Nathan

0

如果包含端口和“--debug-brk”参数,您应该可以调试摩卡单元测试。我在launch.json文件中有以下设置。我还包括“ - 递归”参数,所以摩卡会在子文件夹中运行所有测试。使用这个配置文件,我只需将我的VS Code调试器设置为使用“调试摩卡测试”配置,我就可以在我的任何测试文件中找到断点。

{ 
    // 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