4

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 have ../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
memstomp
  • 43
  • 5

4 Answers4

1

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?

peller
  • 4,435
  • 19
  • 21
  • I've moved my /tests/... directory into util/doh/ and have run the same command "java -jar ..\shrinksafe\js.jar runner.js testModule=tests.module" and I still have the same issue. I've also tried an updated version of js.jar and the dojo-1.4.0 runner.js. Nothing had gotten better. – memstomp Jan 21 '10 at 19:31
  • Sorry, I have moved the /tests folder to be a peer (not child this time) of util/doh/ and it still fails – memstomp Jan 21 '10 at 20:07
  • ok, one more thing... try renaming your 'tests' directory and all the tests.* references to something else... I don't know where it is, but I think tests.* maps to dojo.* When you run the runner.js with its default dojo tests, it references them all as tests.* Dijit and DojoX tests don't do this. Sounds like something which needs to be cleaned up! – peller Jan 21 '10 at 22:46
  • I've renamed everything and still nothing. I have noticed that removing the 'testModule=....' parameters does cause DOH to look in the dojo.* dir though. As well, adding the parameter testUrl=..., the error output changes slightly to: ...\util\doh>java -jar ..\shrinksafe\js.jar runner.js testUrl=tests\module.js testModule=tests.module js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defined. js: "..\..\dojo\dojo.js", line 16: exception from uncaught JavaScript throw: Error: Could not load 'tests.functions.functions'; last tried '../tests/functions/f unctions.js' – memstomp Jan 22 '10 at 16:41
  • I took the files you listed above, put them in a peer directory called 'tests' and it failed. I renamed the directory to 'foo' along with all the tests.* -> foo.* and it worked. – peller Jan 22 '10 at 18:58
  • What was the exact command you used? "java -jar ..\shrinksafe\js.jar runner.js testModule=foo.module" ? Are you using dojo-1.3.2's version of DOH? I've moved and renamed everything like you've mentioned. Is it possible that it has something to do with my version of js.jar or runner.js? – memstomp Jan 22 '10 at 19:31
  • Updated both the js.jar and runner.js, and I still am having issues. I am at a loss now. Thank you for all the help it really is appreciated, do you know possibly anything else that might be preventing this from working? – memstomp Jan 22 '10 at 19:43
  • Everything works correctly now. Thank you very much. I believe that my current dojo-1.3.2 was incomplete or tampered from the original form. Once I reacquired dojo-1.4.0-src and ran the command everything was corrected. Thank you for all the help again! Final command used (for anyone stumbling upon this same issue and is lost): testFolder should be stored in your dojo-release-x.x.x\ directory and the command-line operation "java -jar ..\shrinksafe\js.jar runner.js testModule=testFolder.moduleName" You may need to download the shrinksafe (or rhino) folder seperately then add it to .../util/ – memstomp Jan 22 '10 at 19:59
  • Great. Glad you finally got it to work. Still, there are at least two problems here: one, that you need to co-locate Dojo and your tests (there's an open ticket on this) and two, you can't call it "tests" (probably should open a ticket on this also) – peller Jan 22 '10 at 22:51
1

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.

0

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/

Andy Balaam
  • 6,423
  • 6
  • 34
  • 37
0

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.

Andy Balaam
  • 6,423
  • 6
  • 34
  • 37