vim, git, aws and other three-letter words

Software Development Notes

Node.js: debug a mocha test

To debug a mocha test with node inspector, use a delay before the 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 launched like this:

mocha -t 10000 --debug

The same approach can be used not only for tests but also for any short-lived node app: just wrap the startup code into the setTimeout() call.

Tags: js