gpt4 book ai didi

intern - 如何运行 intern 来测试使用 node.js 运行的 dojo 应用程序?

转载 作者:行者123 更新时间:2023-12-02 00:06:07 29 4
gpt4 key购买 nike

我正在尝试使用 intern 来测试在 node.js 下运行的 dojo 应用程序

我的 intern.js 配置文件是这样的:

define({
loader: {
packages: [
{ name: 'elenajs', location: 'lib' },
{ name: 'tests', location: 'tests' }
],
map: {
'elenajs': { dojo: 'node_modules/dojo' },
'tests': { dojo: 'node_modules/dojo' }
}
},
suites: [ 'tests/all' ]});

当我尝试使用 node node_modules/intern/client.js config=tests/intern 运行测试时,出现此错误:错误:节点插件加载失败,因为环境不是 Node.js

通常我会用类似的东西配置 dojo

dojoConfig = {
...
hasCache: {
"host-node": 1, // Ensure we "force" the loader into Node.js mode
"dom": 0 // Ensure that none of the code assumes we have a DOM
},
...
};

我该如何与实习生一起解决这个问题?

最佳答案

您遇到的问题是由于 Dojo 中的代码依赖于从 Dojo 加载器设置的特定规则,但这不会发生,因为 Dojo 加载器未在使用中。有几个潜在的解决方法:

  1. 由于 Intern 的加载器设置了一些相同的规则,您可以加载 intern/node_modules/dojo/has 并运行 has.add('dojo-has-api', true) 在尝试加载您的 dojo/has 模块之前。这应该会导致 Dojo 使用来自 Intern 加载器的 has.js 实现(并采用它已经设置的所有规则,目前包括 host-node)。执行此操作的最佳位置是 Intern 配置文件,它最终会是这样的:

    define([ 'intern/dojo/has' ], function (has) {
    has.add('dojo-has-api', true);

    return {
    // your existing Intern configuration object…
    };
    });
  2. 在加载任何调用 has('host-node') 的模块之前,加载 dojo/hasintern/node_modules/dojo/has 并调用 dojoHas.add('host-node', internHas('host-node'))(或者我猜你可以硬编码:))。这需要使用加载程序插件来代替您的 suites 数组:

    // tests/preload.js
    define({
    load: function (id, require, callback) {
    require([ 'dojo/has' ], function (has) {
    has.add('host-node', true);
    require(id.split(/\s*,\s*/), callback);
    }
    }
    });

    然后您的 suites 将更改为 suites: [ 'tests/preload!tests/all,tests/foo,tests/bar' ]

Dojo 代码所依赖的任何其他由 Dojo 加载器设置的 has-rules 都需要您自己设置。 Dojo 从其自身的其他部分添加的任何其他规则都将正常工作。

关于intern - 如何运行 intern 来测试使用 node.js 运行的 dojo 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18329026/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com