You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
outputting coverage when process.exit() is called #2
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.
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 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?
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.
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)?
Activity
schuay commentedon Oct 27, 2017
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
bcoe commentedon Oct 28, 2017
@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?
bcoe commentedon Oct 28, 2017
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.TimothyGu commentedon Oct 28, 2017
How about
process.on('beforeExit')?bcoe commentedon Oct 29, 2017
@TimothyGu good idea, I called
unrefon the socket connecting to the inspector, and switched to abeforeExithandler:#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),beforeExitdoes not fire (am I missing something, haven't used this hook before)?this is definitely progress!
bcoe commentedon Nov 22, 2017
there's an event that fires when a script finishes execution that we can wire into.
Preparing package as bbc8 (bcoe#2)