我在我的测试模块中有一些调试器语句,我想在设置了 --debug-brk
的情况下运行 mocha 并点击我的断点,以便我可以检查我的模块的状态。不幸的是,每当我使用此选项运行 mocha 时,下一行都会出现空白光标。我可以输入文本,但似乎没有任何东西在处理我的命令(它肯定不像 Node 调试器):
$ mocha --debug-brk tests.js -R spec
debugger listening on port 5858
[BLANK CURSOR]
我在启动 mocha 的方式上做错了吗?
最佳答案
更新
As of mocha 7.0.0 , --debug-brk
已被删除,取而代之的是 --inspect-brk
使用最新版本的 nodejs ( >=v6.3.0 ) 和 mocha ( >=3.1.0 ),您可以使用 V8 inspector integration .
V8 Inspector integration allows attaching Chrome DevTools to Node.js instances for debugging and profiling
用法
--inspect
激活 V8 检查器集成,--debug-brk
在开头添加断点。由于nodejs v7.6.0和 mocha v3.3.0 ,您可以使用 --inspect --debug-brk
--inspect-brk
简写
$ mocha --debug-brk --inspect
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/@62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
使用 npm 脚本
如果你有一个使用 mocha 的 npm 测试脚本,你可以通过使用 选项结束分隔符将选项从 npm 传递到你的 mocha 脚本 --
:
$ npm test -- --inspect --debug-brk
Chrome 提示
不要每次都复制粘贴网址,而是转到 chrome://inspect
并单击“远程目标”部分中的相应链接。
关于javascript - 使用 mocha 的 --debug-brk 开关启用 Node 调试器的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14352608/