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

Surprising handling of CLI include/exclude compared to nyc #204

Open
coreyfarrell opened this issue Mar 17, 2020 · 1 comment
Open

Surprising handling of CLI include/exclude compared to nyc #204

coreyfarrell opened this issue Mar 17, 2020 · 1 comment
Labels
bug help wanted Issue is well defined but needs assignment p2

Comments

@coreyfarrell
Copy link

  • Version: 7.1.0
  • Platform: Fedora 30 x86_64

I'm working on an experimental loader hook for nyc to provide coverage of ES modules. Initially my scripts looked like:

{
  "test": "c8 --include index.js -r none node test/index.js | tap-yaml-summary",
  "posttest": "c8 report"
}

Running c8 report in a follow-up process was done to allow the text report to display in color (piping into tap-yaml-summary would normally disable color).

I was surprised to find that the --include index.js (restricting by include) did not work. It seems include/exclude options have no effect on coverage collection, instead it only controls coverage reporting. Once I moved the --include index.js to the c8 report it produced the expected report.

I don't know if the functionality can be improved or if this could just be documented. Maybe recommend against controlling include/exclude using CLI arguments in favor of .c8rc.json?

@j03m
Copy link
Collaborator

j03m commented Mar 30, 2020

I think if I am understanding correctly, this is "works as 'currently' designed" but agree it is confusing and should be documented. When c8 enables "coverage" it does so by telling node to do so via an environment variable (see https://github.com/bcoe/c8/blob/master/bin/c8.js#L36, you could supply it from the command line as well). Node then enables coverage on v8 via (I think...) the devtools protocol. Coverage is then written to a temp dir for everything that is flexed. I don't think there is a way to signal to node/v8 that it should only write data for specific files (to my current knowledge anyway).

c8 report then acts as a filter on the raw coverage data for what makes it into a report. In a sense, with -r none the --include flag is sort of a noop/invalid. (maybe we should verify and assert/warn on that). I guess the simplest way to support the expectation in the issue is to support a post-run, pre-report culling of the blobs based on include/exclude.

Edit to add: Or a command that more explicitly indicates the desire to run in two stages, like c8 cache-coverage that explicitly culls the output post run.

@bcoe thoughts?

@bcoe bcoe added bug p2 help wanted Issue is well defined but needs assignment labels Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted Issue is well defined but needs assignment p2
Projects
None yet
Development

No branches or pull requests

3 participants