Simple TypeScript Testing with Chutzpah not Working
我正在尝试使用
1 2 3 4 5 | class Simple { public easyTest() { return 5; } } |
这是规格:
1 2 3 4 5 6 7 8 | /// <reference path="../../../scripts/typings/jasmine/jasmine.d.ts" /> /// <reference path="../../../src/typescript/classSimple.ts" /> describe("Simple Calculations", () => { it("should return true", () => { var simpl = new Simple(); expect(simpl.easyTest()).toBe(5); }); }); |
这是我的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | { "RootReferencePathMode":"SettingsFileDirectory", "Framework":"jasmine", "Compile": { "Mode":"External", "Extensions": [".ts" ], "ExtensionsWithNoOutput": [".d.ts" ] }, "References": [ {"Path":"../../../src/typescript/classSimple.ts" } ], "Tests": [ {"Path":"simpleSpec.ts" } ], "EnableTracing": true } |
这是文件夹结构
1 2 3 4 5 6 7 8 9 | TestProject.sln -src --typescript ---classSimple.ts -tests --jasmine ---typescript ----chutzpah.json ----simpleSpec.ts |
此VS.NET项目设置为在保存时编译
Message:Chutzpah run started in mode Execution with parallelism set to
4 Message:Building test context for
C:\\dev\\TestProject\\tests\\jasmine\\typescript\\simpleSpec.ts
Message:Building test context for
'C:\\dev\\TestProject\\tests\\jasmine\\typescript\\simpleSpec.ts'
Message:Test file
c:\\dev\\TestProject\\tests\\jasmine\\typescript\\simplespec.ts matched test
file path from settings file Message:Investigating reference file path
'../../../src/typescript/classSimple.ts' Message:Added file
'C:\\dev\\TestProject\\src\\typescript\\classSimple.ts' to referenced
files. Local: True, IncludeInTestHarness: True Message:Processing
referenced file 'C:\\dev\\TestProject\\src\\typescript\\classSimple.ts' for
expanded references Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\jasmine\\v2\\jasmine_favicon.png' to referenced files Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\jasmine\\v2\\boot.js'
to referenced files Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\jasmine\\v2\\jasmine-html.js'
to referenced files Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\jasmine\\v2\\jasmine.js'
to referenced files Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\jasmine\\v2\\jasmine.css'
to referenced files Message:Added framework dependency
'C:\\Users\\myself\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\Extensions\\mfv4e3ra.luv\\TestFiles\\chutzpah_boot.js'
to referenced files Message:Finished building test context for
C:\\dev\\TestProject\\tests\\jasmine\\typescript\\simpleSpec.ts Error: 0 :
Time:22:47:48.6888513; Thread:23; Message:Can't find location for
generated path on C:\\dev\\TestProject\\src\\typescript\\classSimple.ts
Warning: 0 : Time:22:47:48.6978503; Thread:23; Message:Chutzpah
determined generated .js files are missing but the compile mode is
External so Chutzpah can't compile them. Test results may be wrong.
Information: 0 : Time:22:47:48.7038522; Thread:23; Message:Found
generated path for
C:\\dev\\TestProject\\tests\\jasmine\\typescript\\simpleSpec.ts at
c:\\dev\\TestProject\\tests\\jasmine\\typescript\\simpleSpec.js Error: 0 :
Time:22:47:48.7088508; Thread:23; Message:Couldn't find generated path
for C:\\dev\\TestProject\\src\\typescript\\classSimple.ts at
就是这样-它只是在最后切断,什么也没发生。事实是,我看到。
的生成路径。
这就像进行单元测试一样简单。我知道测试工作独立于
我做错了什么?
感谢您发布非常详细的repro。您遇到了我见过几次的问题。由于chutzpah.json嵌套在测试文件夹中,因此您需要指定chutzpah用于确定如何从源文件夹映射到输出文件夹的文件夹路径映射。为此,只需将chutzpah.json更改为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | { "RootReferencePathMode":"SettingsFileDirectory", "Framework":"jasmine", "Compile": { "Mode":"External", "Extensions": [".ts" ], "ExtensionsWithNoOutput": [".d.ts" ], "Paths": [ {"SourcePath":"../../../","OutputPath":"../../../"} ] }, "References": [ {"Path":"../../../src/typescript/classSimple.ts" } ], "Tests": [ {"Path":"simpleSpec.ts" } ], "EnableTracing": true, "TraceFilePath":"trace.txt" } |
另一种解决方法是将chutzpah.json放在项目的根目录下。
我需要研究使Chutzpah更好地避免这种情况。我想我会考虑在这种情况下让chutzpah只是假设文件位于同一位置以避免这种常见的陷阱。
Google引导我在这里遇到类似问题:
我的Chutzpah项目中的一些新测试是用TypeScript编写的,并被编译为单个
tsconfig.json
1 2 3 4 5 6 7 | "compilerOptions": { "noImplicitAny": true, "target":"es5", "module":"none", "outFile":"./Tests/mytests-ts.js", "sourceMap": true } |
Chutzpah找不到
1 | Chutzpah Error: System.IO.FileNotFoundException: Couldn't find generated path for D:\\Code\\ChutzpahProject\\Scripts\\DateServiceMock.ts |
直到我使用
chutzpah.json
1 2 3 4 5 6 7 8 | "Compile": { "Extensions": [".ts" ], "ExtensionsWithNoOutput": [".d.ts" ], "Executable":"build-ts.cmd", "Paths": [ {"OutputPath":"Tests/mytests-tests-ts.js" } ] }, |
这感觉可能是对@ matthew-manela的回答的评论...我想。