node.js - 使用 Visual Studio Code 的 Mocha 断点

标签 node.js visual-studio-code mocha.js tdd

是否可以使用 Visual Studio Code 向 Mocha 测试添加断点?

通常在调试代码时,需要配置launch.json,将程序属性设置为Javascript文件执行。不过,我不确定如何为 Mocha 执行此操作。

最佳答案

您知道吗,您只需进入启动配置,将光标放在其他配置之后或之间,然后按 ctrl-space 即可获得自动生成当前有效的 mocha 配置?

这对我来说非常好。包括在断点处停止。 (我也有一个以前的,现在已经过时了,由于各种与设置相关的原因,它不再适用了。)

enter image description here

从 VSCode 1.21.1(2018 年 3 月)开始,这会产生:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Mocha (Test single file)",
      "type": "node",
      "request": "launch",
      "runtimeArgs": [
        "${workspaceRoot}/node_modules/.bin/mocha",
        "--inspect-brk",
        "${relativeFile}",
      ],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "port": 9229
    }
}

附注:debug-brk is deprectated (至少适用于 Node >= 版本 8 的任何人)。

关于node.js - 使用 Visual Studio Code 的 Mocha 断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30023736/

相关文章:

javascript - loopback-storage-component 如何显示图片-文件

node.js - 在 Mocha 中 describe() 的作用是什么?

unit-testing - 在模型上 stub Mongoose 保存方法

post - Mocha 测试(POST 请求): error outside of test suite

node.js - 当我在不同的系统上运行 `package-lock.json` 时,为什么会得到不同的 `npm install` 文件

javascript - socket.io,动态添加消息处理程序

javascript - 从 &lt;iframe&gt; 或 <object> 中获取变量的值

javascript - 使用 node js 执行命令行

visual-studio-code - Visual Studio Code 是否支持用 C# 编写的语言服务器

flutter - Dart 如何放置断点或调试器