【发布时间】:2015-08-07 10:34:02
【问题描述】:
我在 Visual Studio 中有一个项目,它使用 typescript 和 requirejs,并在 Chutzpah 的帮助下运行 QUnit 测试。
我项目中的文件夹结构基本上是这样的:
- chutzpah.json
- app/
- index.html
- js/
- config.js
- main.ts
- Module.ts
- tests/
- Test1.ts
到目前为止,我已经配置了 requirejs,因此在我的所有导入中,我必须使用 app/js/Module,例如,加载那个。 测试也运行良好。
现在,我已将我的 requirejs 配置更改为在 app 文件夹中使用 js 的 baseUrl,因此我可以只使用“模块”进行导入。应用程序本身运行良好,但我无法让测试正常工作。 使用我当前的 chutzpah.json,它似乎想从 ../tests/ 加载测试文件,因此对于 Test1 示例,它需要加载 ../tests/Test1.js
这是我的 config.js:
require.config({
baseUrl: 'js',
paths: {
'swfJQ': '../libs/js/swfJQ'
},
shim: {
'swfJQ': {
"exports": "swfJQ"
}
}
});
这是我的 chutzpah.json:
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"TypeScriptModuleKind": "AMD",
"Tests": [ { "Path": "tests", "Includes": [ "*Tests.ts" ] } ],
"AMDBaseUrl": "js",
"AMDAppDirectory": "app",
"References": [
{ "Path": "app/libs/js/jquery.js", "IsTestFrameworkFile": true },
{ "Path": "app/libs/require.js", "IsTestFrameworkFile": true },
{ "Path": "app/config.js" },
{ "Path": "require.d.ts", "IncludeInTestHarness": false },
{ "Path": "qunit.d.ts", "IncludeInTestHarness": false },
{ "Path": "tests", "IncludeInTestHarness": false, "Excludes": ["*.html"] },
{ "Path": "app/js", "IncludeInTestHarness": false }
],
"EnableCodeCoverage ": "true",
"CodeCoverageIncludes": [
"*app/js/*"
],
"CodeCoverageExcludes": [
"app/libs/*",
"tests/*"
]
}
这是测试文件之一:
import Replay = require('../app/js/Module');
QUnit.module("Module tests");
test("Module.constructor", function (assert: QUnitAssert) { /* stuff */ }
我认为 require('../app/js/Module') 或多或少是罪魁祸首,并将范围设置为 ../,但如果我以其他方式编写代码,打字稿编译器将无法编译. 我想这可能是我很容易错过的东西,但我无法固定它。
也许这不是我遇到的胆大妄为的问题,但我的一般 Typescript 设置应该不同(所以我不必在我的测试文件中使用 require('../app ... '))?
【问题讨论】:
标签: requirejs typescript chutzpah