2013-12-02

Node.js - how to debug mocha test with node inspector

Node.js - how to debug mocha test with node inspector

Update: found a much better method: just run mocha with --debug and --debug-brk parameters and then open node-inspector:

$ mocha --debug --debug-brk

Old method: to debug mocha test with node inspector use the delay before test:

beforeEach(function(done) {
    //start mocha as
    //mocha -t 10000 --debug
    setTimeout(function() {
        done();
    }, 5000);
});

This way there are 5 seconds to start the node inspector and set a breakpoint. Mocha should be lauched as this:

$ mocha -t 10000 --debug

Same approach can be used not only for tests but for any short-living node app - just wrap the startup code into the setTimeout() call.

No comments:

Post a Comment