IntelliJ and nodeunit

It turns out that I’ve gotten completely side tracked…or maybe not side tracked per se, but at least not completely focused on the client side of the Application. The past couple of weeks I’ve been engulfed in Node. Trying to figure out what it is, what I can do with it and obviously how I can test drive it. I found nodeunit which seemed to be a good testing framework candidate.

Command Line

Running nodeunit tests from the command line is trivial:

This is all fine and dandy but…I’ve gotten used to doing all of this from within my IDE. I run IntelliJ, for better or worse, and I want to be able to run the tests as well as the debugger from that environment.

IntelliJ

I spent way too much time on this, when in fact it turned out to be really simple. Sometimes I wish I were smarter. There is an IntelliJ plugin for Node which enables you to create Run/Debug Configurations for NodeJS sources so I installed that. When I finally(!) examined the nodeunit executable, it turned out to be a one-liner shell script running node with nodeunit as it’s first argument. It’s really just a short cut. I would have saved quite some time if I had figured that out sooner.


This makes the Run Configuration trivial and actually running the test equally trivial.

There isn’t more to it than that.

4 responses on “IntelliJ and nodeunit

  1. Hi Daniel,

    we also use node as a server-side-language. Our first try was node-unit as a testing-framework. Then we switched to jasmine (which has a jasmine-node). Jasmine mimics the rspec-language on the node side, the test are very elegant. Both frameworks have the problem of implmenting the asynchronity of node. They use an implizit (node-unit via counts) or explicit (jasmine via asyncWait) waiting mechanism. Finally we used vows. The framework uses the same mechanimen for testing as node for processes: callbacks. It integrates very well in the new philosophy. There is steep learning curve, because vows don’t mimics synchronous testing, but you will learn vows and node-style-programming-with-callcacks at once.

    best regards
    jens

    PS: If you code your node-code with coffee-script you will get a very elegant solution

    1. Jens,
      During my first pass trying to find a testing framework I touched on Vows and it looked really promising. However, I started out with nodeunit since it had concepts I could relate to, like the setUp() and tearDown() for example. I will definitely go back and look more at Vows.
      Coffee-script is on my list of things to look at as well.
      Thanks,
      /Daniel

  2. Thanks for this – so far its the only way I found to debug javascript unit tests in IDEA. Currently (July 2012) IDEA supports unit testing (eg. jsTestDriver and nodeunit) and debugging, but not both at the same time! Using the above IDEA thinks it is debugging a javascript app (nodeunit) which happens to run tests.

Comments are closed.