gpt4 book ai didi

javascript - 在 Intern 中加载项目目录外的依赖项

转载 作者:可可西里 更新时间:2023-11-01 01:26:15 24 4
gpt4 key购买 nike

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>

如何从我的其他项目中包含这些外部文件?

最佳答案

可能是我想的太简单了,但是我是这样想的:

  • project1 是一个项目
  • project2 是一个项目
  • intern_tests 是一个项目

达到你想达到的目的:

cd /path/to/project1/
npm link

cd /path/to/project2/
npm link

cd /path/to/intern_tests/
npm install project1 project2

您现在的项目结构如下:

intern_tests/
node_modules/
project1
project2
tests/
unit/
functional/

关于javascript - 在 Intern 中加载项目目录外的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33505646/

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