Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to start debugger on exception or test failure in node.js?

What I am looking for is basically nosetest --pdb --pdb-failures from nose testing framework.

I am using mocha for testing. What I'd like to do is to run tests like

mocha --break-on-exception --break-on-failure that would stop executing tests once encountering exception or assertion failure, would start node-inspector for me and would allow me to introspect runninng code.

Is this possible anywhere in node.js world, with any library or test framework?

like image 595
Almad Avatar asked Nov 11 '13 00:11

Almad


People also ask

How do I debug Node js errors?

But, for me, the easier & quicker solution is to run the application in debug mode with --inspect option, with Chrome debugger to inspect it (no breakpoints), with Pause on Exceptions option enabled. That's all you need to do.

How do I start node debugger?

Open up Preferences > Settings and in the search box type in “node debug”. Under the Extensions tab there should be one extension titled “Node debug”. From here, click the first box: Debug > Node: Auto Attach and set the drop down to “on”. You're almost ready to go now.

How do you debug test cases in node js?

To do this right-click the project in Solution Explorer/Open Command Prompt Here… Then enter: npm install mocha --save-dev. In Visual Studio, add a JavaScript Mocha Unit Test file (in Solution Explorer right-click the project/Add/New Item..). Debugging tests won't work with a regular JavaScript file.


1 Answers

add this line to your test:

if (global.v8debug)
   global.v8debug.Debug.setBreakOnException()

start with mocha --debug-brk, connect node-inspector, continue and wait for exception

like image 151
Andrey Sidorov Avatar answered Sep 22 '22 17:09

Andrey Sidorov