Repository navigation
outputting coverage when process.exit() is called #2
Description
Activity
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.
@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 ofprocess.exit()seems to hang the Node process...process.exitis 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 thatinspector.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?
digging into this a bit more, I was able to get things to terminate in
process.exit()but by the time we've hitprocess.exit()I believe the inspector session is already terminated so it's not possible to usespawnSyncto communicate with the parent process.How about
process.on('beforeExit')?@TimothyGu good idea, I called
unrefon the socket connecting to the inspector, and switched to abeforeExithandler: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),beforeExitdoes not fire (am I missing something, haven't used this hook before)?this is definitely progress!
there's an event that fires when a script finishes execution that we can wire into.
- added a commit that references this issue
on Mar 17, 2020
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
spawnSyncto output coverage in a subprocess.CC: @schuay, @bmeck