简体   繁体   English

伊斯坦布尔代码覆盖从Node访问的信息

[英]Istanbul Code Coverage information access from Node

Context 上下文

I am developing living-tests for Node.js. 我正在为Node.js开发生活测试 In that context I am not so much interested in how things are normally done, but how they can be done better, so by necessity different. 在这种情况下,我对通常如何完成事情并不是那么感兴趣,而是如何更好地完成它们,因此必然会有所不同。

Problem 问题

From a javascript test script, I want to be able to specify what some test code is intended to cover. 从javascript测试脚本,我希望能够指定一些测试代码要涵盖的内容。 So let's say I have a File prototype, and I want to test the path property. 所以假设我有一个File原型,我想测试path属性。 Just before the code that exercises this property, I want to in some way specify that is what is being tested. 就在执行此属性的代码之前,我想以某种方式指定正在测试的内容。 Then after that code runs, I want to specify it is completed. 然后在该代码运行之后,我想指定它已完成。 In between those points, when the code is being exercised, I don't want to count any of the code coverage that covered anything else other than that property. 在这些点之间,当执行代码时,我不想计算除了该属性之外的任何其他任何代码覆盖。 This way a developer can ensure something was not merely covered incidentally, which can help developers to understand about what they have and have not thoroughly tested. 通过这种方式,开发人员可以确保某些内容不仅仅是偶然覆盖,这可以帮助开发人员了解他们拥有的内容并且没有经过全面测试。 This is intended to partially address the issue of code coverage not necessarily meaning something is well tested. 这是为了部分解决代码覆盖问题,而不一定意味着某些东西经过了充分测试。

Approach 途径

As far as I can tell, Istanbul is the only commonly used and recommended code coverage tool for javascript, so I am currently forcusing on using that tool. 据我所知,伊斯坦布尔是javascript唯一常用和推荐的代码覆盖工具,因此我目前正在使用该工具。 I know you have to start Istanbul before you start node, so it can instrument your code. 我知道你必须在启动节点之前启动伊斯坦布尔,因此它可以检测你的代码。 However, I suspect that as long as that has been done, the code that is running in node should be able to access code coverage information about what has been covered so far. 但是,我怀疑只要已经完成,节点中运行的代码应该能够访问到目前为止已覆盖的内容的代码覆盖率信息。 I'm pretty sure if I can do that I can figure out how to use it to accomplish what I want. 我很确定如果我能做到这一点,我可以弄清楚如何使用它来实现我想要的。

How can I access code coverage information from javascript? 如何从javascript访问代码覆盖率信息?

The question is asking for something that doesn't solve the problem... 问题是要求一些不能解决问题的东西......

You can access the information from coverage.json after triggering the code coverage run. 您可以在触发代码覆盖率运行后访问coverage.json中的信息。 See https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md 请参阅https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md

But what you need, I think, is some other algorithm. 但我认为,你需要的是其他一些算法。 You specify it as "I want to in some way specify that is what is being tested." 您将其指定为“我希望以某种方式指定正在测试的内容”。 which is unfortunately too vague to recommend anything. 不幸的是,太过模糊,无法推荐任何东西。

Code coverage tools just watch what gets executed during tests and mark everything else as "untested". 代码覆盖工具只是观察测试期间执行的内容,并将其他所有内容标记为“未经测试”。 No more logic there. 没有更多的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM