【发布时间】:2016-02-03 23:46:42
【问题描述】:
this question 的答案没有回答我的问题。
我想使用 Intern 作为我的测试框架从我的项目根目录外部加载依赖项。我目前正在使用以下目录结构:
www/
project1/
app/
lib/
project2/
app/
lib/
intern-tests/
node_modules/
tests/
functional/
project1-tests/
project2-tests/
unit/
project1-tests/
project2-tests/
intern.js
Gruntfile.js
如您所见,我正在创建 intern-tests 自己的项目,并希望此目录保存 所有我对 所有我的项目的测试。我已经设置了我的 Gruntfile 以使用 grunt exec 库执行测试,将 grunt projectName 命令转换为 grunt test --project=projectName。一切正常,但我的单元测试无法加载 project1/ 和 project2/ 目录中的依赖项。
例如,这是我的单元测试之一:
define([
'intern!object',
'intern/chai!assert',
'jquery',
'../../../../project2/lib/js/var/document',
'../../../../project2/lib/js/exports/file/functions/resizeInput'
], function(registerSuite, assert, $, document, resizeInput) {
registerSuite({
name: 'functions',
resizeInput: function() {
var $input = $(document.createElement('input'));
resizeInput($input, 8, 20, 450, 200);
assert.equal($input.width(), 450);
}
});
});
并运行该测试给我以下错误:
SUITE ERROR
Error: Failed to load module ../project2/lib/js/var/document from
project2/lib/js/var/document.js (parent: tests/unit/project2/functions)
at HTMLScriptElement.handler <__intern\node_modules\dojo\loader.js:517:27>
如何从我的其他项目中包含这些外部文件?
【问题讨论】:
-
您是否考虑过将其他项目作为实习生测试项目的子模块,或者这只会使您的实习生测试项目规模过大?
-
标签: javascript unit-testing dojo amd intern