c8 icon indicating copy to clipboard operation
c8 copied to clipboard

Modify coverage ranges for code run in VM

Open skerit opened this issue 1 year ago • 3 comments

  • Version: v20.8.1
  • Platform: Linux 6.6.4-arch1-1

I run certain code like this:

let head = '(function(module, exports, require, __dirname, __filename, ' + argument_config.names.join(', ') + ') {"use strict";\n';

let exported_function = libvm.runInThisContext(head + source + '\n/**/})', {
	filename: path,
	lineOffset: -1,
});

And contrary to nyc, c8 is able to create coverage for this. Unfortunately, because of the added header the coverage positions are wrong.

Would it be possible for c8 to use the lineOffset or columnOffset property somehow?

skerit avatar Mar 15 '24 13:03 skerit

Try wrapperLength https://github.com/bcoe/c8/blob/main/index.d.ts#L20

cenfun avatar Mar 17 '24 12:03 cenfun

wrapperLength is more like a global setting, not something that you can specify for code run using the vm module. If being able to dynamically set the wrapper length using comments like /* c8 wrapper-length 47 */ that would be great. Or just being able to "reset" the column count maybe like /* c8 end wrapper */

skerit avatar Mar 17 '24 13:03 skerit