Dojo’s DOH requires a web server to run tests in a browser. But never fear:
$ cd ~/code/dojo
docs dojo util
$ python -m SimpleHTTPServer &
$ xdg-open http://localhost:8000/util/doh/runner.html
Note that you will see some test failures, because the python web server doesn’t do PHP.
$ kill %1
to stop your web server.
On Python 3, use this instead of the SimpleHTTPServer line:
python3 -m http.server &
Yes, Python includes a little web server that serves files in your current directory. Batteries included. Thanks to Lyle Backenroth and commandlinefu for making me aware of this.
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.
Imagine your code is somewhere different from dojo, and another library you use is somewhere else:
Yes, you need a config file. Imagine it’s at C:/code/mycode/dohconfig.js and it looks like this:
"org/me" : "../../../code/mycode/org/me",
"org/them" : "../../../code/mycode/org/them/nicelib"
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
- java -jar – run Java and execute a JAR file.
- C:/libs/dojo/dojo/dojo.js – the Dojo “loader” – unlike in 1.6 and earlier, you don’t run DOH’s runner.js. Instead you run dojo.js and pass “load=doh” as an argument.
- baseUrl=file:///C:/libs/dojo/dojo – a URL form of the location of the directory that contains dojo.js.
- load=file:///C:/code/mycode/dohconfig.js – the location of your config file, which defines the “paths” variable, previously (in 1.6) known as registerModulePaths. This variable helps Dojo find your code based on its module name (here “org/me”).
- load=doh – after you’ve read (actually, executed) the config file, execute DOH.
- test=org/me/mytests/mytestmodule – the module name of your test (not the path – a module name which can be found using the lookups in the paths defined in your config file).