row*_*ow1 8 jasmine chutzpah typescript
我正在使用TypeScript 1.0与Visual Studio 2012,Chutzpah 3.2.1.1和Jasmine 2.
我有一个非常基本的测试编译很好,但没有使用Visual Studio Chutzpah测试适配器或命令行传递.
我收到以下错误
ReferenceError:无法找到变量:MyProject in ....
我的项目结构如下:
**solution**
TypeScriptProject
X.ts
TestProject
chutzpah.json
compile.bat
Scripts\(contains typings)
Spec
TestX.ts
Run Code Online (Sandbox Code Playgroud)
TypeScriptProject\X.ts
module MyProject {
export class X {
getValue(): number {
return 5;
}
}
}
Run Code Online (Sandbox Code Playgroud)
TestProject\chutzpah.json
{
"Framework": "jasmine",
"Compile": {
"Extensions": [".ts"],
"ExtensionsWithNoOutput": [".d.ts"],
"Executable": "compile.bat"
},
"References": [
{ "Path": "../TypeScriptProject/X.ts"}
],
"Tests": [
{ "Path": "Spec"}
]
}
Run Code Online (Sandbox Code Playgroud)
TestProject \的compile.bat
@echo off
tsc Spec/TestX.ts ../TypeScriptProject/X.ts --sourcemap
Run Code Online (Sandbox Code Playgroud)
TestProject \规格\ TestX.ts
/// <reference path="../Scripts/typings/jasmine/jasmine.d.ts"/>
/// <reference path="../../TypeScriptProject/X.ts"/>
describe("test x value", function(){
it("should", function(){
var x = new MyProject.X();
expect(x.getValue()).toEqual(5);
});
});
Run Code Online (Sandbox Code Playgroud)
由于它编译得很好,TestX.ts中的引用应该是正确的.
我的问题似乎与Chutzpah在TFS 2012中运行Jasmine无法找到被测试的参考文件,因为我在Visual Studio测试运行器中得到错误,似乎在谈论使用Team Build.
默认情况下,Chutzpah假设编译的source和out目录是chutzpah.json文件的位置.但是,在您的情况下,这些目录应该高一个,因为您正在编译不在chutzpah.json文件位置或低于chutzpah.json文件位置的.ts文件.
因此,通过将sourcedirectory和outdirectory添加到编译设置,它将正常工作:
{
"Framework": "jasmine",
"Compile": {
"Extensions": [".ts"],
"ExtensionsWithNoOutput": [".d.ts"],
"Executable": "compile.bat",
"SourceDirectory": "../",
"OutDirectory": "../",
},
"References": [
{ "Path": "../TypeScriptProject/X.ts"}
],
"Tests": [
{ "Path": "Spec"}
]
}
Run Code Online (Sandbox Code Playgroud)