Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging jasmine-node tests with node-inspector

Does anyone have any idea if this is possible? Most of the sample for node-inspector seemed geared toward debugging an invoked webpage. I'd like to be able to debug jasmine-node tests though.

like image 549
j03m Avatar asked May 28 '11 16:05

j03m


People also ask

How do I run a node in debugging?

Open the starting file (typically index. js ), activate the Run and Debug pane, and click the Run and Debug Node. js (F5) button. The debugging screen is similar to Chrome DevTools with a Variables, Watch, Call stack, Loaded scripts, and Breakpoints list.


2 Answers

In short, just debug jasmine-node:

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js spec/my_spec.js 

If you look at the source of the jasmine-node script, it just invokes cli.js, and I found I could debug that script just fine.

I wanted to use node-inspector to debug a CoffeeScript test. Just adding the --coffee switch worked nicely, e.g.

node --debug-brk node_modules/jasmine-node/lib/jasmine-node/cli.js --coffee spec/my_spec.coffee 
like image 66
Ian Avatar answered Oct 13 '22 02:10

Ian


I ended up writing a little util called toggle:

require('tty').setRawMode(true); var stdin = process.openStdin();  exports.toggle = function(fireThis) {     if (process.argv.indexOf("debug")!=-1)     {         console.log("debug flag found, press any key to start or rerun. Press 'ctrl-c' to cancel out!");         stdin.on('keypress', function (chunk, key) {             if (key.name == 'c' && key.ctrl == true)             {                 process.exit();             }             fireThis();         });     }     else     {         console.log("Running, press any key to rerun or ctrl-c to exit.");         fireThis();         stdin.on('keypress', function (chunk, key) {             if (key.name == 'c' && key.ctrl == true)             {                 process.exit();             }             fireThis();         });        } } 

You can drop it into your unit tests like:

var toggle = require('./toggle');  toggle.toggle(function(){      var vows = require('vows'),     assert = require('assert');      vows.describe('Redis Mass Data Storage').addBatch({  .... 

And then run your tests like: node --debug myfile.js debug. If you run debug toggle will wait until you anything but ctrl-c. Ctrl-c exits. You can also rerun, which is nice.

w0000t.

like image 44
j03m Avatar answered Oct 13 '22 04:10

j03m