出于某种原因,我所有(甚至是基本的)尝试使用 Chutzpah、TypeScript 和 RequireJS 设置单元测试都失败了。
我根据示例尝试了几种组合,但要么出现超时错误,要么出现文件未找到错误(对我来说没有任何意义,因为它是 Chutzpah 生成的文件)。我的猜测是它只是一些小东西(尽管可能不容易找到),所以也许有人知道我如何解决这个错误。
测试文件
/// <reference path="../../../typings/qunit/qunit.d.ts" />
/// <reference path="../../../typings/requirejs/require.d.ts" />
define([], () => {
QUnit.module('DefineTests2');
test('foo', () => {
equal(0, 0);
});
});
输出
------ Test started: File: C:\Users\...\test.DefineTests2.ts ------
Error: Error opening c:/users/.../Scripts/Game/Tests/Utilities/_Chutzpah.164.test.DefineTests2.js: The system cannot find the path specified.
While Running:C:\Users\...\Scripts\Game\Tests\Utilities\test.DefineTests2.ts
Error: Timeout occurred when executing test file
While Running:C:\Users\...\Scripts\Game\Tests\Utilities\test.DefineTests2.ts
========== Total Tests: 0 passed, 0 failed, 0 total ==========
chutzpah.json
{
"Framework": "qunit",
"TestHarnessReferenceMode": "AMD",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"TypeScriptModuleKind": "AMD",
"AMDBasePath": "Scripts/Game",
"References": [
{ "Path": "Scripts/deps/requirejs/require.js" },
{ "Path" : "config.js" }
]
}
配置.js
require.config({
paths: {},
shim: {}
});
显然,这已经是一个非常精简的版本,所以希望对于有更多 Chutzpah 经验的人来说,任何错误都应该很容易找到。
[补充]
将编译模式更改为外部后(感谢 Matthew Manela),路径看起来好一些,但还是有问题,我之前没有注意到,在我写这篇文章时另外用点替换,显示的路径缺少两个目录在它的中间。
------ Test started: File: C:\Users\MyName\Source\Repos\MySolutionName\Main\MyProjectName\Scripts\Game\Tests\Utilities\test.DefineTests2.ts ------
Error: Error opening C:/Users/MyName/Source/Repos/MyProjectName/Scripts/Game/Tests/Utilities/test.DefineTests2.js: The system cannot find the path specified.
While Running:C:\Users\MyName\Source\Repos\MySolutionName\Main\MyProjectName\Scripts\Game\Tests\Utilities\test.DefineTests2.ts
Error: Timeout occurred when executing test file
While Running:C:\Users\MyName\Source\Repos\MySolutionName\Main\MyProjectName\Scripts\Game\Tests\Utilities\test.DefineTests2.ts
========== Total Tests: 0 passed, 0 failed, 0 total ==========
“打开错误”行的路径稍有错误,缺少 \MySolutionName\Main,这解释了为什么找不到文件。chutzpah.json 位于 MyProjectName 下,因此即使是 TestHarnessLocationMode 等设置也不应该与此相关。