Skip to content
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

Modify coverage ranges for code run in VM #524

Open
skerit opened this issue Mar 15, 2024 · 3 comments
Open

Modify coverage ranges for code run in VM #524

skerit opened this issue Mar 15, 2024 · 3 comments

Comments

@skerit
Copy link

skerit commented Mar 15, 2024

  • 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?

@cenfun
Copy link
Contributor

cenfun commented Mar 17, 2024

@skerit
Copy link
Author

skerit commented Mar 17, 2024

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 */

@ericmorand
Copy link

What is the point, ultimately? Covering the code provided as source?

Also, how would your idea work with your example? You don't know the length of the wrapper at build time:

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

The length depend on the argument_config runtime value. What value would you set in the c8 wrapper-length pragma?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants