简体   繁体   中英

Istanbul Code Coverage information access from Node

Context

I am developing living-tests for 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. So let's say I have a File prototype, and I want to test the path property. 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. 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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