coverage: expose native V8 coverage by bcoe · Pull Request #22527 · nodejs/node (original) (raw)
This pull request is again part of an ongoing initiative to improve the Node.js for those building developer tools (CC: @bengl, @boneskull).
What is this?
For some time now, V8 has exposed test coverage through the inspector protocol. This pull request makes it possible to have this information output to disk by setting the environment variable NODE_V8_COVERAGE=./coverage-directory
.
By moving this logic into Node.js itself, we're able to better hook process.exit()
, signal-handling, and child_process.spawn()
; this is awesome, because this behavior was previously facilitated by a handful of horrible hacks:
Going forward a tool similar to nyc will simply be able to consume the raw V8 coverage information, and output Istanbul coverage reports.
Help with code review
@nodejs/v8-inspector I rely on some of the behavior that the inspector API is currently exhibiting, mainly that coverage is output in a single tick of the event loop:
session.post('Profiler.takePreciseCoverage', (err, coverageInfo) => {
try {
if (err) throw err;
writeFileSync(target, JSON.stringify(coverageInfo));
} catch (err) {
console.error(err);
}
});
It would be wonderful to have some folks double check my work.
I'm also looping in several folks who've been involved with Istanbul and nyc over the years.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes- tests and/or benchmarks are included
- documentation is changed or added
- commit message follows commit guidelines