-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Support statement coverage #54530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see at least two issues with doing this:
Of course there is some code complexity to doing this too. While I agree that statement coverage would be nice to have, I haven't seen any users of the test runner asking for it either. My understanding (which @MoLow seemed to confirm) is that C8 does not report this metric from V8 coverage. If they aren't doing it, I don't see a great reason for us to do it either. |
The latest version of C8 can do this with c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js As an alternative, we can also use the custom test reporter node --test-reporter=node-monocart-coverage --test tests Indeed, it is extremely complicated and hurt performance.
Check TypeScript coverage job in CI |
If this was implemented directly in V8, whole JS/Node ecosystem could benefit from this. Adding AST based coverage analysis is not ideal for performance. |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
This is pretty important since basically every other coverage tool in the ecosystem has this 4th metric. Perhaps it would make more sense to see if someone can contribute it to v8 directly? That way all of the valid downsides listed in #54530 (comment) wouldn't apply. |
The compromise is that the Node test runner can export all the native V8 coverage data, as well as the source code and sourcemap, in custom reports const { Transform } = require('node:stream');
const customReporter = new Transform({
writableObjectMode: true,
transform(event, encoding, callback) {
switch (event.type) {
// ...
case 'test:coverage': {
const { rawV8CoverageData, sourcesAndSourcemaps } = event.data;
break;
}
}
},
});
module.exports = customReporter; |
Uh oh!
There was an error while loading. Please reload this page.
I think the Node.js coverage reporter should include support for reporting statement coverage.
My idea is to parse the source code into an Abstract Syntax Tree (AST) using
acorn-walk
, and then use theStatement
callback to extract statements. They could then be converted toCoverageStatement
s, (similarly to how thegetLines
function works with lines toCoverageLines
).These statements could then be mapped to ranges in the same way that lines are handled in
mapRangeToLines
.I saw a (extremely complicated) way of doing this in https://github.com/cenfun/monocart-coverage-reports/, so it appears to be possible.
The text was updated successfully, but these errors were encountered: