DOH 对 Dojo 根目录之外的 JavaScript 函数进行命令行测试

发布于 2024-08-19 09:45:54 字数 1422 浏览 2 评论 0原文

我正在尝试从 dojo-1.3.2 运行 DOH 以从命令行测试简单的 Javascript 函数。然而,我似乎无法运行任何东西,而且网络似乎没有 DOH 命令行文档。

理想情况下,我想要的结构是:

测试驻留在: C:\myproject\tests\

Dojo 驻留: C:\dojo-1.3.2\util\doh

截至目前,我已经在 ..\doh\tests 中进行了一个简单的测试,

我尝试在 ..\doh 目录中运行:

java -jar .. \shrinksafe\js.jar runner.js testModule=tests.module

每次我得到:

js:未捕获的 JavaScript 运行时异常:ReferenceError:“window”未定义 编辑。 发生异常:错误:无法加载“tests.module”; 最后尝试过“tests/module.js” 0 个测试在 0 个组中运行

有什么我应该做却遗漏的事情吗?我还尝试使用 dojoUrl= 指向 dojo.js 文件,但仍然出现相同的错误。

据我所知,我的测试没有在任何地方使用窗口。我有三个文件:

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;
};

我也尝试过重组目录让 ../dojo-1.3.2/ 包含测试。从命令提示符运行与上面相同的命令同样会失败。 目录结构:

/dojo-1.3.2

   /dojo
   /tests
   ...
   /util

      /shrinksafe
      ...
      /doh

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫弦 2024-08-26 09:45:54

不确定“窗口”来自哪里,但我认为 doh 无法在 Dojo 目录之外的测试中正常工作。如果您将 util/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?

美胚控场 2024-08-26 09:45:54

如果您希望 testFolder 存储在默认的 dojo-release-xxx\ 目录之外。
将以下内容添加到您的命令中:
registerModulePath=tests,../myproject/tests

您可能需要正确编辑 ../ 才能找到实际的目录结构。

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.

煞人兵器 2024-08-26 09:45:54

这里有一个补丁: http://bugs.dojotoolkit.org/ticket/10511 允许在 dojo 根目录之外运行命令行测试,但无论如何,它似乎并未在 dojo-1.6.1 中应用。

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.

寄意 2024-08-26 09:45:54

可以在命令行上运行 DOH 测试,包括 dojo 源代码树之外的测试。创建一个配置文件,如下所示,说明您的代码模块相对于 dojo/util/doh 位置:

require({
    paths: {
        "org/myorg" : "../../../mycode/org/myorg",
        "com/mycom" : "../../../x/com/mycom"
    }
});

并将其命名为 config.js。打开命令窗口并 cd 进入包含“dijit”、“dojo”、“dojox”和“util”目录的目录。运行此命令:

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

完整的答案在这里: http://dojotoolkit.org/reference -guide/1.9/util/doh.html

这里有更详细的解释:http://www.artificialworlds.net/blog/2012/10/09/running-dojo-doh-unit-使用犀牛在命令行上进行测试/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文