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:
- 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.
- Install Node.js. YETI requires Node.js. Please refer to the Node.js documentation for downloading and building Node
- 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.
- Install YETI: npm install yeti
- 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
- Create a file called autotest.watchr and put the following ruby into it: https://gist.github.com/738737#file_autotest.watchr
- 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
- 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:
- In your terminal, launch Watchr: watchr autotest.watchr
- Edit /lib/example.js so Y.example is no longer set to “foo”, e.g., Y.example = “bar”;
- Save /lib/example.js and view your terminal. You should see YETI’s output of the failing test results
- Edit /lib/example.js resetting Y.example to “foo”, save, and note YETI’s output of the successful test results
- 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:
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 🙂
Great to hear from you, Ted. The last Jehu show? Amazing!
Does the oauth table in the yql repo do what you need?
https://github.com/yql/yql-tables/blob/master/oauth/oauth.xml
Lemme know