GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — coverage: expose native V8 coverage by bcoe · Pull Request #22527 · nodejs/node

Conversation

@bcoe

@bcoe bcoe commented Aug 25, 2018

Copy link
Copy Markdown
Contributor

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:

  • spawn-wrap.
  • signal-exit.

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.

@isaacs, @addaleax, @schuay.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antsmartian, bricss, pedrocarrico, boneskull, marvinhagemeister, hashseed, robertrossmann, laggingreflex, styfle, emzinnia, and 6 more reacted with thumbs up emoji jokester reacted with heart emoji
All reactions
  • 👍 16 reactions
  • ❤️ 1 reaction
@bcoe bcoe added semver-minor PRs that contain new features and should be released in the next minor version. test Issues and PRs related to Node.js core tests and test infrastructure. inspector Issues and PRs related to the V8 inspector protocol. labels Aug 25, 2018
@nodejs-github-bot

nodejs-github-bot commented Aug 25, 2018

Copy link
Copy Markdown
Collaborator

@bcoe build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/674/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs involving general changes in the lib/ or src/ directories. label Aug 25, 2018
@bcoe
bcoe requested review from MylesBorins, Trott and addaleax August 25, 2018 23:05
@bcoe
bcoe force-pushed the coverage branch from 97a6c65 to 03a7833 Compare August 25, 2018 23:11
devsnek
devsnek previously requested changes Aug 25, 2018
View reviewed changes
Comment thread lib/child_process.js Outdated

@devsnek devsnek Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to stop this from happening?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Aug 25, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is not at this time? any recommendations.

It's almost always the case that you will be setting NODE_V8_COVERAGE in the context of running a test suite, and that you'd probably like to er on the side of the variable propagating, even though it's pretty common in tests to selectively set env, e.g., maybe your test is exercising a specific environment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@devsnek devsnek Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure it's quite common, but we should support both sides. perhaps checking if the property already exists (so you can set it to an empty string) would work.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Aug 26, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a smart idea, I was thinking even for our own test suite we might want to be able to remove the variable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/cli.md Outdated

@devsnek devsnek Aug 25, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neither the link nor the addition here explain what to do with the output coverage file. Generally people just use the inspector UI. does the output file even have a governed format? do we have to semver major when v8 changes the format?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Aug 25, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally people just use the inspector UI

I would argue it's very rare for people writing command line tools and modules to interact with the inspector, as evidenced by the fact that nyc has over 31,000 dependents and continues to grow in popularity (getting downloaded over 400,000 times a week) despite native test coverage having been available for quite some time.

As the lead maintainer of nyc and Istanbul, I would love to move people away from using these libraries when writing Node.js applications, and towards V8's coverage -- but I think the burden of kicking off and interacting with an inspector session is a usability rough-edge that will prevent adoption.

do we have to semver major when v8 changes the format?

I think you're right that we should point users to a breakdown of what to expect in the output format -- @schuay can you recommend a better document to link to.

The output format is standardized in V8, and I don't expect that there will be major breaking changes to it (and if there are it will be very rare).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR and marvinhagemeister reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@devsnek devsnek Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I wasn't clear. I'm saying there need to be docs for the format available from the node docs, not that people should only use the inspector UI. the link you have doesn't give any docs on the format of the file.

On the semver-major front, I just want to make sure we're careful, if you think it's fine that's good enough for me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bcoe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@bcoe bcoe Aug 26, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's let @schuay or someone else on V8's side chime in too (@TimothyGu?), I think your concern is valid and it would be good to have someone speak to how stable the API is on the Chromium side of things.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@TimothyGu TimothyGu Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not too involved in the V8 development process… though it might be telling that the coverage API is already in the RC version of the devtools protocol without an Experimental flag on.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@schuay schuay Aug 27, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this 👍

The inspector protocol documentation here is the source of truth. In particular, takePreciseCoverage will return an array of ScriptCoverage objects.

I'm not sure what DevTools' policies on protocol changes are. You could try asking on their mailing list: https://groups.google.com/forum/#!forum/google-chrome-developer-tools. For V8 coverage specifically, we currently don't have any changes in the output format planned that I'm aware of.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hashseed hashseed Aug 29, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we are very careful with changing CDP due to backwards compatibility concerns. Unless unavoidable, we will not change the coverage format. If that happens however, the CDP version would be bumped as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TimothyGu reacted with hooray emoji TimothyGu and BridgeAR reacted with heart emoji
All reactions
  • 🎉 1 reaction
  • ❤️ 2 reactions
addaleax
addaleax reviewed Aug 26, 2018
View reviewed changes
Comment thread lib/internal/process/coverage.js Outdated

@addaleax addaleax Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to account for the worker thread id here, and test interaction with it, as well…

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Aug 26, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind expanding a bit, pseudo code would be awesome 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, I’m asking for require('internal/worker').threadId to be part of the format string here :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

devsnek reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread test/parallel/test-v8-coverage.js Outdated

@addaleax addaleax Aug 26, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try to avoid using static message parameters for assertions, and use comments instead – most of the time, a static message string just hides the most useful information (the actual values in the assertion)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bcoe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
vsemozhetbyt
vsemozhetbyt reviewed Aug 26, 2018
View reviewed changes
Comment thread doc/api/cli.md Outdated

@vsemozhetbyt vsemozhetbyt Aug 26, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this reference should go after [REPL]: repl.html in ASCII sort order.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/cli.md Outdated

@vsemozhetbyt vsemozhetbyt Aug 26, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: `child_process.spawn` -> `child_process.spawn()`

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vmarchaud vmarchaud mentioned this pull request Aug 26, 2018
expose gc event as inspector's runtime event nodejs/diagnostics#220
Closed
@bcoe
bcoe force-pushed the coverage branch from 193ab84 to fc3e539 Compare August 27, 2018 22:14
devsnek
devsnek reviewed Aug 28, 2018
View reviewed changes
Comment thread lib/child_process.js Outdated

@devsnek devsnek Aug 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use Object.prototype.hasOwnProperty.call

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devsnek
devsnek dismissed their stale review August 28, 2018 01:32

changes

addaleax
addaleax approved these changes Aug 28, 2018
View reviewed changes
Comment thread doc/api/cli.md Outdated

@addaleax addaleax Aug 28, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, would an object with a single entry make sense? That would leaves a bit of room for adding more information, e.g. metadata?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Aug 28, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the object is shaped like this:

{
  "results": [ScriptCoverage, ScriptCoverage]
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Aug 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, great – that just wasn’t obvious from the documentation :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bcoe

bcoe commented Aug 29, 2018

Copy link
Copy Markdown
Contributor Author

@nodejs/testing 👋 thought this would be pertinent to your interests -- a next logical step once this lands would be moving Node.js' test coverage over to the approach. I've benchmarked it and it's 300% faster 😮

marvinhagemeister, TimothyGu, BridgeAR, and OmgImAlexis reacted with thumbs up emoji
All reactions
  • 👍 4 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@evanlucas

evanlucas commented Aug 29, 2018

Copy link
Copy Markdown
Contributor

I’m super thrilled to see this! Awesome work!

marvinhagemeister reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

evanlucas
evanlucas reviewed Aug 29, 2018
View reviewed changes
Comment thread lib/internal/process/coverage.js Outdated

@evanlucas evanlucas Aug 29, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the recursive option?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bcoe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@bcoe bcoe Aug 29, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to switch to recursive as soon as this issue is resolved, and we know the shape of the API won't be changing.

This is actually a perfect example of why mkdirp is a good addition to the API :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Trott

Trott commented Aug 31, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

I suspect some members of @nodejs/build may be familiar with coverage stuff. Ping!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR reviewed Aug 31, 2018
View reviewed changes
Comment thread lib/child_process.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No-blocking nit: !options.env || !Object.prototype.hasOwnProperty.call(options.env, 'NODE_V8_COVERAGE')

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/api/cli.md Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a note that this is currently not supported for worker threads is likely a good thing as people might otherwise maybe run into this as long as it's not supported.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should also be documented that the coverage generation can be deactivated for specific child processes by explicitly setting the env flag to an empty string.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/process/coverage.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this one line up would be better:

if (err) return console.error(err);
try { ... } catch (err) { ... }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-v8-coverage.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be written with for of loops instead:

for (const coverageFile of coverageFiles) {
  ...
  for (const fixtureCoverage of coverage.result) {
    ...
  }
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/parallel/test-v8-coverage.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use the object spread notation instead of using a helper function here.

{ env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/process/coverage.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of the condition is not possible to reach: either there is no inspector in which case the session is empty or the session will be set (if that would not be the case, the property access below would throw).

And should we not log an error here? I would be surprised if I pass in the environment variable but the coverage files are not generated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/process/coverage.js Outdated

@BridgeAR BridgeAR Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to throw in error in this case. Otherwise the user would not know that no data will be collected.

In that case the hasInspector check in writeCoverage would also be obsolete.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not a fan of throwing here. If necessary, we can print a warning, but in practice, this situation really only occurs within Workers (for now).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Sep 4, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a warning, which I feel is a reasonable compromise; It would be miserable to be unable to run your test suite with coverage because executing code in a worker results in exceptions being thrown.

When we support workers in the future, perhaps we could switch to throwing an exception?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
rvagg
rvagg reviewed Aug 31, 2018
View reviewed changes
Comment thread lib/child_process.js Outdated

@rvagg rvagg Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad indentation

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rvagg

rvagg commented Aug 31, 2018

Copy link
Copy Markdown
Member

I imagine this will let us replace lib/internal/process/write-coverage.js functionality, does that have to be a separate step?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hashseed
hashseed reviewed Aug 31, 2018
View reviewed changes
Comment thread lib/internal/process/coverage.js Outdated

@hashseed hashseed Aug 31, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also expose a way to use other coverage modes? This primarily has performance implications. E.g. callCount: false would allow a function to be inlined after it has been covered. detailed: true would not require coverage-related bytecode to be emitted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@schuay schuay Aug 31, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue for simplicity, exposing only the most detailed mode, and making sure it is as fast as possible. callCount: true / detailed: true should also allow inlining (it does require special bytecode emission though).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bcoe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@bcoe bcoe Sep 3, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with @schuay on this one, I'd lean towards starting simple. I can imagine following up with the option for more complex configuration.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hashseed
hashseed approved these changes Aug 31, 2018
View reviewed changes
@addaleax

addaleax commented Sep 2, 2018

Copy link
Copy Markdown
Member

@bcoe Heads up, this needs a rebase (presumably around the options help texts being moved to lib/internal/print_help.js)

bcoe reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bcoe

bcoe commented Sep 3, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@rvagg I'd like to replace write-coverage.js and the instrumentation process we apply with this approach eventually (it will most likely be the thing I work on immediately after we land this, with @addaleax's help).

I'd prefer to spread this out over two pull requests, for a few reasons:

  1. a few tests will need to be debugged and potentially rewritten a bit; specifically tests that exercise async_hooks are having trouble passing in Node's suite, because they mock some of the internal libraries used by the inspector.
  2. all the coverage bits in the Makefile will need to be rewritten and fiddled with.
  3. I need to actually write the dependent library that easily converts from the inspector format to the format consumed by our reports (I have most of the pieces written, but it will be easier to finish off this dependency once we land this work).

tldr; I think there are enough sticky bits to getting Node consuming the inspector coverage format, that it will be easier to consume across two pull requests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bcoe
bcoe force-pushed the coverage branch from d128c9e to 5370fec Compare September 3, 2018 04:49
BridgeAR
BridgeAR approved these changes Sep 4, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with my last two comments addressed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/process/coverage.js Outdated

@BridgeAR BridgeAR Sep 4, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an error exists, the code should not continue, otherwise the write would still be triggered.

Adding a return statement fixes this: if (err) return console.error(err);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/process/coverage.js Outdated

@BridgeAR BridgeAR Sep 4, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The session check can not be reached due to either being set to a truthy value if the inspector is present, or not being set and the setup function throws and the code does not continue. If the latter is the case, the writeCoverage function is never called at all.

Therefore it's safe to remove this check as well.

I missed that the function is exported.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
evanlucas
evanlucas approved these changes Sep 4, 2018
View reviewed changes
jasnell
jasnell reviewed Sep 4, 2018
View reviewed changes
Comment thread test/parallel/test-v8-coverage.js Outdated

@jasnell jasnell Sep 4, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the console.info() statements part of the test or purely informational? If informational, I'd prefer to omit them and use code comments instead. If they are part of the test, then please add a comment indicating that so that they are not accidentally removed later.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bcoe bcoe Sep 4, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a new build environment that fails for coverage, added since I last ran the suite. This is purely to see what the heck is going on:

node-test-commit-linux-containered

will remove as soon as I see what the underlying exception is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Benjamin Coe
coverage: expose native V8 coverage
0ec2a60
native V8 coverage reports can now be written to disk by setting the
variable NODE_V8_COVERAGE=dir
@bcoe
bcoe force-pushed the coverage branch from c5188e1 to 0ec2a60 Compare September 5, 2018 00:40
rvagg
rvagg approved these changes Sep 5, 2018
View reviewed changes
@bcoe

bcoe commented Sep 5, 2018

Copy link
Copy Markdown
Contributor Author

I believe comments have been addressed, and I intend to land this in the next day or so 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bcoe

bcoe commented Sep 5, 2018 •
edited by BridgeAR
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

ci: https://ci.nodejs.org/job/node-test-pull-request/17021/ ✔️

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 5, 2018
@bcoe bcoe changed the title coverage: expose native V8 coverage test: expose native V8 coverage Sep 5, 2018
@bcoe bcoe changed the title test: expose native V8 coverage coverage: expose native V8 coverage Sep 5, 2018
bcoe pushed a commit that referenced this pull request Sep 5, 2018
Benjamin Coe
coverage: expose native V8 coverage
c9d6e3f
native V8 coverage reports can now be written to disk by setting the
variable NODE_V8_COVERAGE=dir

PR-URL: #22527
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yang Guo <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
@bcoe

bcoe commented Sep 5, 2018

Copy link
Copy Markdown
Contributor Author

Landed in c9d6e3f

styfle reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bcoe bcoe closed this Sep 5, 2018
targos pushed a commit that referenced this pull request Sep 5, 2018
Benjamin Coe @targos
coverage: expose native V8 coverage
9a0dad2
native V8 coverage reports can now be written to disk by setting the
variable NODE_V8_COVERAGE=dir

PR-URL: #22527
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yang Guo <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
@bcoe
bcoe deleted the coverage branch September 5, 2018 18:30
targos added a commit that referenced this pull request Sep 5, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
8a45a6c
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22394
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22392
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
@targos targos mentioned this pull request Sep 5, 2018
Release proposal: v10.10.0 #22716
Merged
targos pushed a commit that referenced this pull request Sep 6, 2018
Benjamin Coe @targos
coverage: expose native V8 coverage
707a37f
native V8 coverage reports can now be written to disk by setting the
variable NODE_V8_COVERAGE=dir

PR-URL: #22527
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Yang Guo <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
814a0c0
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
cdb3598
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
targos added a commit that referenced this pull request Sep 6, 2018
@targos
2018-09-06, Version 10.10.0 (Current)
ed976d7
Notable changes:

* child_process:
  * `TypedArray` and `DataView` values are now accepted as input by
    `execFileSync` and `spawnSync`. #22409
* coverage:
  * Native V8 code coverage information can now be output to disk by setting the
    environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
  * The bundled npm was upgraded to version 6.4.1. #22591
    * Changelogs:
      [6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
      [6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
      [6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
      [6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
  * The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
    `fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
    `DataView` objects. #22150
  * A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
    `fs.readdirSync`. If set to true, the methods return an array of directory
    entries. These are objects that can be used to determine the type of each
    entry and filter them based on that without calling `fs.stat`. #22020
* http2:
  * The `http2` module is no longer experimental. #22466
* os:
  * Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
    manipulate the scheduling priority of processes. #22407
* process:
  * Added `process.allowedNodeEnvironmentFlags`. This object can be used to
    programmatically validate and list flags that are allowed in the
    `NODE_OPTIONS` environment variable. #19335
* src:
  * Deprecated option variables in public C++ API. #22515
  * Refactored options parsing. #22392
* vm:
  * Added `vm.compileFunction`, a method to create new JavaScript functions from
    a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
  * [lundibundi](https://github.com/lundibundi) - Denys Otrishko

PR-URL: #22716
This was referenced Sep 6, 2018
2018-09-06 Version 10.10.0 (Current) @targos beevelop/docker-android-nodejs#236
Closed
2018-09-06 Version 10.10.0 (Current) @targos beevelop/docker-nodejs#221
Closed
@bcoe bcoe mentioned this pull request Sep 8, 2018
feat: switch to using Node's built in coverage bcoe/c8#22
Merged
@addaleax addaleax added the coverage Issues and PRs related to Node.js code coverage support. label Sep 18, 2018
@OmgImAlexis OmgImAlexis mentioned this pull request Sep 20, 2018
todo: figure out how to instrument .mjs files istanbuljs/nyc#659
Open
@kt3k kt3k mentioned this pull request Jan 20, 2019
feature-request: first-class test-coverage support denoland/deno#106
Closed
@cidrblock cidrblock mentioned this pull request Jun 22, 2026
feat: Add built-in V8 code coverage support for VS Code extension testing webdriverio-community/wdio-vscode-service#163
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell left review comments
@addaleax addaleax addaleax approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
@Trott Trott Awaiting requested review from Trott
@MylesBorins MylesBorins Awaiting requested review from MylesBorins
+7 more reviewers
@schuay schuay schuay left review comments
@TimothyGu TimothyGu TimothyGu left review comments
@devsnek devsnek devsnek left review comments
@vsemozhetbyt vsemozhetbyt vsemozhetbyt left review comments
@rvagg rvagg rvagg approved these changes
@evanlucas evanlucas evanlucas approved these changes
@hashseed hashseed hashseed approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. coverage Issues and PRs related to Node.js code coverage support. inspector Issues and PRs related to the V8 inspector protocol. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. semver-minor PRs that contain new features and should be released in the next minor version. test Issues and PRs related to Node.js core tests and test infrastructure.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

13 participants

@bcoe @nodejs-github-bot @evanlucas @Trott @rvagg @addaleax @schuay @jasnell @TimothyGu @hashseed @devsnek @BridgeAR @vsemozhetbyt
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.