Skip to content

outputting coverage when process.exit() is called #2

Description

@bcoe

I think @chrisdickonson came up with a good idea for how to approach this, if we capture an event on process.exit, we'll use spawnSync to output coverage in a subprocess.

const client = await CRI({port: port})
const {Profiler} = client

process.on('exit', () => {
  process.spawnSync('ws-write-coverage.js', ())
  client.close()
})

CC: @schuay, @bmeck

Activity

  1. schuay commented on Oct 27, 2017

    @schuay

    It'd be awesome to solve this using the current V8 API; but if that turns out to be a bad solution I could imagine emitting an inspector event on Isolate teardown containing all remaining coverage information. Just an idea so far, not sure how happy inspector folks would be about that.

    cc @hashseed, @caseq

  2. bcoe commented on Oct 28, 2017

    @bcoe
    OwnerAuthor

    @schuay looping in @TimothyGu and @eugeneo, who look to have done a chunk of the work on the Inspector binding in Node.js.

    The approach I outlined above doesn't quite work. Calling inspector.close() in the context of process.exit() seems to hang the Node process... process.exit is a weird method, in that it can only perform synchronous operations, and the even loop is guaranteed to exit on the next tick (my guess is that inspector.close() steps on the toes of the shutdown process).

    Even though this is potentially a bug we can fix in Node, as you point out @schuay, it might be a bit nicer to change around the API a bit so that you can more easily execute an operation as soon as your application has completed execution; maybe I'm just missing something?

  3. bcoe commented on Oct 28, 2017

    @bcoe
    OwnerAuthor

    digging into this a bit more, I was able to get things to terminate in process.exit() but by the time we've hit process.exit() I believe the inspector session is already terminated so it's not possible to use spawnSync to communicate with the parent process.

  4. TimothyGu commented on Oct 28, 2017

    @TimothyGu
    Contributor
  5. bcoe commented on Oct 29, 2017

    @bcoe
    OwnerAuthor

    @TimothyGu good idea, I called unref on the socket connecting to the inspector, and switched to a beforeExit handler:

    #4

    This seems to work well if the application exits normally, or if the application throws an exception. If the program exits due to a process.exit(0), beforeExit does not fire (am I missing something, haven't used this hook before)?

    this is definitely progress!

  6. bcoe commented on Nov 22, 2017

    @bcoe
    OwnerAuthor

    there's an event that fires when a script finishes execution that we can wire into.

  7. added a commit that references this issue on Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions