2016-05-15 27 views
1

我想运行最基本的TypeScript测试使用JasmineChutzpah,我只是不能得到它的工作。这里是源文件:简单的TypeScript测试与Chutzpah不工作

class Simple { 
    public easyTest() { 
     return 5; 
    } 
} 

这里是规格:

/// <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); 
    }); 
}); 

这里是我的chutzpah.json文件:

{ 
    "RootReferencePathMode": "SettingsFileDirectory", 
    "Framework": "jasmine", 
    "Compile": { 
     "Mode": "External", 
     "Extensions": [ ".ts" ], 
     "ExtensionsWithNoOutput": [ ".d.ts" ] 
    }, 
    "References": [   
     { "Path": "../../../src/typescript/classSimple.ts" }   
    ], 
    "Tests": [ 
     { "Path": "simpleSpec.ts" } 
    ], 
    "EnableTracing": true 
} 

这里是文件夹结构

TestProject.sln 
-src 
--typescript 
---classSimple.ts 
-tests 
--jasmine 
---typescript 
----chutzpah.json 
----simpleSpec.ts 

这VS.NET p roject被设置为在保存时编译TypeScript,并且我在物理上在classSimple.ts旁边的完全相同的目录中查看传输的JavaScript输出:classSimple.js。然而,当我运行使用Chutzpah我得到以下规范:

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

这就是它 - 它只是切断与结束,没有任何反应。事情是,我看到了。 js文件在上述追踪内规定的位置准确地,但放肆声称找不到生成的路径...

这是因为它得到了单元测试一样简单。我知道测试独立于.ts文件工作,因为如果我运行.js文件测试通过。

我在做什么不正确?

回答

2

感谢您发布非常详细的报告。你碰到一个我看过几次的问题。由于chutzpah.json嵌套在测试文件夹中,因此需要指定chutzpah用于确定如何从源映射到输出文件夹的文件夹路径映射。要做到这一点只需更改您的chutzpah.json到:

{ 
    "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只是假设文件共存以避免这种常见的陷阱。

+1

我做了一项修改,以确保将来人们不会遇到这个问题:https://github.com/mmanela/chutzpah/commit/9328f3d5f546cecc0ebf8f010b455519324c3de8 –

+0

这很好。感谢您花时间调查并将更新推送到GitHub。我显然没有得到这样的设置。 – atconway

0

谷歌使我这里一个类似的问题:

在我放肆的项目一些新的测试都写在打字稿并编译成一个单一的outfile

tsconfig。JSON

"compilerOptions": { 
    "noImplicitAny": true, 
    "target": "es5", 
    "module": "none", 
    "outFile": "./Tests/mytests-ts.js", 
    "sourceMap": true 
    } 

放肆找不到*.ts文件

Chutzpah Error: System.IO.FileNotFoundException: Couldn't find generated path for D:\Code\ChutzpahProject\Scripts\DateServiceMock.ts 

,直到我用了Paths选项:

chutzpah.json

"Compile": { 
    "Extensions": [ ".ts" ], 
    "ExtensionsWithNoOutput": [ ".d.ts" ], 
    "Executable": "build-ts.cmd", 
    "Paths": [ 
     { "OutputPath": "Tests/mytests-tests-ts.js" } 
    ] 
    }, 

这种感觉就像这可能是对@马修·马内拉的答案的评论......我想。

相关问题