Running Dojo 1.7+ DOH unit tests on the command line with Rhino

October 09, 2012 [Dojo, JavaScript, Tech, Test Driven]

To run your own DOH-based unit tests on the command line using Rhino:

NOTE: this is Dojo 1.7 and above. For 1.6, there was a whole other cryptic incantation.

Project layout

Imagine your code is somewhere different from dojo, and another library you use is somewhere else:

C:/code/mycode/org/me/mytests/
                             ...
                             mytestmodule.js
                             ...
C:/code/mycode/org/them/nicelib/
                             ...
C:/libs/dojo/dojo/
                 ...
                 dojo.js
                 ...
             dijit/
                 ...
             dojox/
                 ...
             util/doh/
                     ...
                     main.js
                     ...

Config file

Yes, you need a config file. Imagine it's at C:/code/mycode/dohconfig.js and it looks like this:

require({
    paths: {
        "org/me" : "../../../code/mycode/org/me",
        "org/them" : "../../../code/mycode/org/them/nicelib"
    }
});

Command line

Now you can run your tests like this:

java -jar C:/libs/dojo/util/shrinksafe/js.jar C:/libs/dojo/dojo/dojo.js baseUrl=file:///C:/libs/dojo/dojo load=file:///C:/code/mycode/dohconfig.js load=doh test=org/me/mytests/mytestmodule

Explanation