Erik's blog

Code, notes, recipes, general musings

Running YETI tests automatically with Watchr

with 2 comments

YETI (YUI Easy Testing Interface) provides an easy, automated way to run YUI 3 tests. Watchr provides an easy way to run arbitrary Ruby based on file system events. Putting the two together, we get an easy way to run YETI when a YUI 3 script is saved.

Prerequisites:

  • Mac 10.6.4.  What follows may work elsewhere, but I haven’t tried it yet

Set up:

  1. Install Watchr. Please refer to the readme file in Watchr’s github repository for installation instructions. I wrote a post the other day about getting started with Watcher on Mac 10.6.4.
  2. Install Node.js.  YETI requires Node.js.  Please refer to the Node.js documentation for downloading and building Node
  3. Install npm.  YETI can be installed easily with npm.  Please refer to the readme file in npm’s github repository for installation instructions.  The Joyent blog also has an informative post on Installing Node and npm.
  4. Install YETI: npm install yeti
  5. Create the following directories: test and lib.  These directory names are completely arbitrary, but they match the watchr script introduced below.  If you want to use different names, please update the watchr script accordingly
  6. Create a file called autotest.watchr and put the following ruby into it: https://gist.github.com/738737#file_autotest.watchr
  7. Create a file called test_example.html in the test directory and put the following html in it: https://gist.github.com/738737#file_test_example.html
  8. Create one last file called example.js in the lib directory and put the following javascript in it: https://gist.github.com/738737#file_example.js

You should now have a file structure like this:
/autotest.watchr
/lib/example.js
/test/test_example.html

Let’s run this rig:

  1. In your terminal, launch Watchr: watchr autotest.watchr
  2. Edit /lib/example.js so Y.example is no longer set to “foo”, e.g., Y.example = “bar”;
  3. Save /lib/example.js and view your terminal.  You should see YETI’s output of the failing test results
    Screen shot of YUI test failure
  4. Edit /lib/example.js resetting Y.example to “foo”, save, and note YETI’s output of the successful test results
    Screen shot of YETI output showing YUI tests passing
  5. Kill watchr (when you’re ready): Ctrl+C

Going forward:

Using the autotest.watchr script above, any file named /test/test_{lib name}.html will be run when /lib/{lib name}.js is edited.  The test file will also be run when it is edited.  If you add a new lib, but do not define a corresponding test file, watchr will fail silently.  Likewise, if you add a test file, but don’t put YUI tests in it.  In short, add libs and YUI tests in pairs, and you’re all good.

In closing, here’s one of my favorite songs from Drive Like Jehu:

Advertisements

Written by Erik

December 13, 2010 at 12:49 am

Posted in tutorial

Tagged with , , , , ,

2 Responses

Subscribe to comments with RSS.

  1. I didn’t know you were a Jehu fan! Shit, we could have chatted about Jehu for house. Here’s a bootleg of Orca. Imagine Jehu with 10 more guitars, bass, and Rick leading a jam session at the old Casbah.
    [audio src="http://music.tdrake.net/orca.mp3" /]

    I went to the last pitchfork, the first jehu, and the last jehu show.

    P.S. I need some help setting up an oAuth YQL table 🙂

    Ted DRAKE

    April 11, 2011 at 8:07 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: