出于某种原因,我用Chutzpah,TypeScript和RequireJS设置单元测试的所有(甚至是基本的)尝试都失败了。
我根据示例尝试了几种组合,但是我收到了超时错误或找不到文件错误(对我来说没有任何意义,因为它是一个Chutzpah生成的文件)。我的猜测是它只是一些小东西(虽然不容易找到,也许),所以也许有人知道如何解决这个错误。
TESTFILE
/// <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" }
]
}
config.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 ==========
&#34;错误打开&#34;有一个稍微错误的路径,它缺少\ MySolutionName \ Main,这解释了为什么它找不到该文件。 chutzpah.json在MyProjectName下,因此即使像TestHarnessLocationMode等设置也不应该与之相关。