打字稿的代码覆盖率 [英] Code Coverage for Typescript

查看:69
本文介绍了打字稿的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚在Typescript中启动了一个项目,我们需要获得代码覆盖率数据。

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

我们现有的JavaScript项目使用Grunt中的Instanbul进行覆盖。我们不确定如何为TypeScript复制它。

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

是否有任何工具可以从TypeScript代码本身生成代码覆盖?
或者我们是否针对生成的JavaScript代码运行伊斯坦布尔(或类似)工具。

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.

推荐答案

在TypeScript团队中,我们只是在编译的JavaScript上使用常规代码覆盖工具。我们发现这已经足够了,因为通常对于代码覆盖率,您正在考虑总覆盖率%(不会发生显着变化)或者在表达级别深度潜水(这也不会发生显着变化)。

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).

如果你发现了一个支持它的工具(我还没有意识到),你理论上可以使用编译器发出的源图来映射覆盖范围数据返回TypeScript代码。这可能不值得这么麻烦。

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.

这篇关于打字稿的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆