benbria / coffee-coverage

Istanbul and JSCoverage-style instrumentation for CoffeeScript files.
MIT License
145 stars 31 forks source link

c8 instrumentor support #98

Closed brewster1134 closed 5 years ago

brewster1134 commented 5 years ago

i recently switched from nyc to c8, which breaks coffee-coverage (it generates strange results). as far as mocha, istanbul, and the command line commands & options went, i just dropped it in, with the only change being replacing nyc with c8 in my package.json scripts

are there any plans on adding c8 support? it seems like its becoming more prominent with node 10.

https://github.com/bcoe/c8

jwalton commented 5 years ago

It would be extremely difficult (probably impossible), to support c8 in coffee-coverage. I believe that Istanbul supports source maps when generating reports these days, though, so you could just use c8, and then use source maps to generate your coverage.

The way istanbul (and coffee-coverage) works is by taking a source file like:

console.log "hello world"

And compiling it with instrumentation:

(__coverage__["/users/jwalton/test.js"].s[0]++, void 0);
console.log("hello world");

We add source lines that use a global variable called __coverage__ to keep track of when each statement, branch, and function are called. Then at the end of your tests, Istanbul dumps the contents of this global variable to a file. When you run your reports, it walks through the generated data and creates a report.

The way c8 works, on the other hand, is to use v8's native code coverage which uses internal counters in V8 to measure when each function is run, and inserts IncBlockCounter bytecodes into the compiled code to track when each block/branch is run. c8 gathers up these counts and creates an output file that's the same format as Istanbul generates, so you can use it to generate reports.

The problem is, there's no easy way for coffee-coverage to manipulate how V8 does code coverage at run time. Your coffee files have already been turned into js long before we get to that point, and we have no ability to manipulate how V8 generates bytecode.