2016-05-15 67 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" } 
    ] 
    }, 

這種感覺就像這可能是對@馬修·馬內拉的答案的評論......我想。

相關問題