I'm trying to run DOH from dojo-1.3.2 to test simple Javascript functions from command-line. However, I can't seem to get anything to run and the net seems to be devoid of DOH command-line documentation.
Ideally the structure I would like is:
Tests reside: C:\myproject\tests\
Dojo reside: C:\dojo-1.3.2\util\doh
As of right now I've put a simple test in ..\doh\tests
I try running while in the ..\doh directory:
java -jar ..\shrinksafe\js.jar runner.js testModule=tests.module
Each time I get:
js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defin ed. An exception occurred: Error: Could not load 'tests.module'; last tried 'tests/module.js' 0 tests to run in 0 groups
Is there something I should be doing that I have left out? I've also tried pointing to the dojo.js file using dojoUrl= but still the same error.
As far as I can see my tests do not use window anywhere. I have three files:
tests/module.js
dojo.provide("tests.module");
dojo.require("tests.functions.functions");
tests/functions/functions.js
dojo.provide("tests.functions.functions");
dojo.require("tests.demoFunctions");
doh.register("tests.functions.functions", [
function test_alwaysTrue(){
doh.assertTrue(tests.demoFunctions.alwaysTrue());
}
]);
tests/demoFunctions.js
dojo.provide("tests.demoFunctions");
tests.demoFunctions.alwaysTrue = function(){
return true;
};
I've also tried restructuring the directory to h开发者_如何学Cave ../dojo-1.3.2/ contain the tests. Running the same command as above from command-prompt fails identically. Dir Structure:
/dojo-1.3.2
/dojo
/tests
...
/util
/shrinksafe
...
/doh
Not sure where the 'window' is coming from, but I don't think doh ever worked properly with tests outside the Dojo directory. Does it work if you copy util/doh to be a peer of your tests directory?
If you want your testFolder to be stored outside the default dojo-release-x.x.x\ directory. Add the following to your command: registerModulePath=tests,../myproject/tests
You may have to edit ../ properly to locate your actual directory structure.
There is a patch here: http://bugs.dojotoolkit.org/ticket/10511 which allows running command-line tests outside of the dojo root, but it does not appear to have been applied, in dojo-1.6.1, anyway.
It is possible to run DOH tests on the command line, including tests outside the dojo source tree. Create a config file like this saying where your code modules are relative to the dojo/util/doh location:
require({
paths: {
"org/myorg" : "../../../mycode/org/myorg",
"com/mycom" : "../../../x/com/mycom"
}
});
and name it config.js. Open a command window and cd into the directory containing the "dijit", "dojo", "dojox" and "util" directories. Run this command:
java -jar util/shrinksafe/js.jar dojo/dojo.js baseUrl=file:///full/path/to/dojo/dojo load=file://full/path/to/config.js load=doh test=com/mycom/tests
The full answer is here: http://dojotoolkit.org/reference-guide/1.9/util/doh.html
There is a more detailed explanation here: http://www.artificialworlds.net/blog/2012/10/09/running-dojo-doh-unit-tests-on-the-command-line-with-rhino/
精彩评论