Unfortunately, as with many other things at Mozilla, there is an abundance of out of date documentaion. The JS Test Library page refers to a Perl script, which appears to be more or less abandoned. Instead, there is a python script 'jstests.py', written by Dave Mandelin in his copious amounts of free time. Unfortunately, the old version of unit testing documentation comes up first when searching for it on Google. Alas.
One thing that is sadly not emphasized is just how easy it is to plug in a different engine to use these tests. In fact, I have a "shell" for Narcissus JS, written in 30-some lines of Python code.
To hook into the testing framework, you need a "shell" that supports two command line options:
It must be possible to support multiple files and strings of code, though this is not a particularly difficult challenge.
- The -x option allows you to ignore a list of tests. Since Mozilla includes tests for special Firefox-only features, you will want to use this.
- The --failure-file option will write the failing unit tests to the specified file, useful as input for the -x option.
On another note, Narcissus now runs without special extensions in Firefox 4. Huzzah! Now to make it interact smoothly with the DOM...