Jstdutil - A Ruby wrapper over JsTestDriver

Today I needed remote access to a gem I've been tinkering with for a while, so I pushed it to Gemcutter. It's called jstdutil, and it provides a small Ruby wrapper over JsTestDriver that adds colored output, a short, snappy `jstestdriver` command and autotest.

Install it

The gem is available on Gemcutter, which requires that you install their gem (and use RubyGems >= 1.3.5):

gem update --system
gem install gemcutter
gem tumble

Then you're ready to install:

gem install jstdutil

Then download the JsTestDriver jar. Put it somewhere safe, like ~/bin/java, and set the environment variable $JSTESTDRIVER_HOME to the directory where you put the file (e.g., export JSTESTDRIVER_HOME=~/bin/java). That's it!

Use it

Now you can run JsTestDriver with `jstestdriver`. For instance, to start the server, you can issue:

jstestdriver --port 4224

Then, run all your tests:

jstestdriver --tests all
# If config is not in cwd:
jstestdriver --config path/to/config.conf --tests all

The output should be nicely colored, even on Windows. If you're not seeing colors on Windows, you need to:

gem install win32console


The best part is autotest. Simply:

# If config is not in cwd:
jsautotest --config path/to/config.conf

Swish! Autotest runs the entire test suite initially, and then waits for any of your files to change. Once a file changes, jstdutil makes some intelligent guesses on which test cases were affected, and runs only the corresponding tests. If you want to rerun the test suite, simply issue Ctrl-C in the shell where autotest is running. Quickly issuing Ctrl-C twice aborts autotest.

A word of warning

As I mentioned, I pushed the gem in need of remote access earlier today. This means that it''s not quite as finished as I had planned, but I've been using it for a few weeks, and it does work great most of the time. If you encounter any issues, please do let me know. Even better: clone the project on Gitorious, or fork it on GitHub and fix it yourself.

Why write a wrapper?

These features could probably easily have been added to the JsTestDriver project itself. In fact, the right thing for me to do would probably be to submit a patch of sorts. However, I enjoy Ruby alot more than Java, and my Java is a bit rusty. I hope JsTestDriver one day incorporates something like this, lessening the burden of installing it (if you're really into colored output and shell autotest like me).

Happy testing, and please to report back any troubles you may encounter!

Follow me on Twitter.

Published 4. November 2009 in javascript, test driven development og ruby.

Possibly related