Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

We've just started a project in Typescript and we need to get code coverage figures.

Our existing JavaScript projects use Instanbul in Grunt for coverage. We are unsure how to replicate this for TypeScript.

Are there any tools for generating code coverage from the TypeScript code itself? Or do we run the Istanbul (or similar) tool against the generated JavaScript code.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You can use Chutzpah for that

With Chutzpah you can run your tests from command line and integrate your tests with Visual Studio Test Explorer.

Chutzpah allows you decide if you want to run the tests from .ts files, .js files, .html files or from all of them.

When set (in Visual Studio/Tools/Options/Chutzpah) to run tests from .ts files, you will be able to analyze code coverage of your generated .js files, with a link between the generated JavaScript code and the .ts file that generated it.

It makes really easy to work on your TypeScript code coverage, even being the JavaScript code the real code under test.

You can install Chutzpah from Visual Studio/Tools/Extensions and updates.

You can find here more details about code coverage using Chutzpah.

share|improve this answer
    
Thanks. We've gone with Chutzpah here and it's working fine for us. –  Gerard Condon Jun 17 '13 at 8:39

i have created sample to generate code coverage for typescript files using karma coverage and karma typescript processor.

https://github.com/nitinbhatia-dev/karma-typescript-coverage

share|improve this answer

On the TypeScript team, we just use regular code coverage tools on the compiled JavaScript. We've found this to be more than sufficient, since usually for code coverage you are looking at total coverage % (which doesn't change significantly) or are deep-diving at expression-level (which also doesn't change significantly).

If you found a tool that supported it (I'm not aware of any yet), you could in theory use the source maps emitted by the compiler to map the coverage data back to the TypeScript code. It's probably not worth the trouble.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.