在未被捕获的错误上,node.js mocha回退到debugging器

有没有一种方法在node.js(理想的摩卡也)模拟python的行为

python -m pdb setup.py test 

如果程序抛出一个未捕获的exception,那么这将回退到debugging接口。

编辑

@robertklep提出了无证的breakOnException命令,看起来非常棒,但在实践中并没有那么多:

test.js

 var hello = {}; function testFunc () { anotherFunct(); } function anotherFunct () { var b = hello.unfound; } testFunc(); 

然后它冻结在:

 $ node debug test.js < Debugger listening on port 5858 connecting to port 5858... ok break in test.js:1 > 1 var hello = {}; 2 function testFunc () { 3 anotherFunct(); debug> breakOnException debug> c debug> backtrace 

EDIT2:test.js首先不会产生错误。 以上工作正常。

将此添加到您的脚本中:

 process.on('uncaughtException', function() { debugger; }); 

并用node debug script.js启动它。 这将使您进入debugging器未捕获的exception/错误。

为了让这个(有点)为摩卡testing工作,你可以添加上面的行,并按照这里的指示(特别是安装node-inspector和启动摩卡使用--debug-brk )。

编辑 :节点debugging器也有能力打破错误/例外:

 $ node debug script.js debug> breakOnException debug> c ...