1. Your 测试模块始终需要编写为 AMD 模块,但您可以测试所需的任何客户端代码。在您的测试模块中,只需像任何其他模块一样将非 AMD 代码指定为依赖项,然后访问脚本创建的全局变量:
define([
'intern!tdd',
'intern/chai!assert',
'intern/order!myPackage/myFoo.js'
], function (tdd, assert /* note, no assignment here */) {
tdd.suite('foo suite', function () {
tdd.test('something in foo', function () {
// accessing a global variable created by `myPackage/myFoo.js`
assert.ok(window.myFoo, 'Global myFoo object should exist');
});
});
});
2. 您不需要在 Intern 配置中执行任何明确的操作即可使其正常工作,除了在suites
array.
3. 对于需要测试的客户端应用程序,建议的目录结构如下所示:
/ - your entire application
src/
index.html - your app’s entry-point HTML
app/ - your app package, containing application-specific JavaScript to be tested
foo.js - Some module `foo`
tests/ - Intern tests for `app`
foo.js - Tests for `foo`
intern.js - Intern configuration for `app`
node_modules/
intern/
当然,这会根据应用程序的架构方式而有所不同,但从“从头开始”的方法来看,这是我们通常推荐的目录结构。