Skip to content

Commit

Permalink
monkeypatch exit as well as reallyExit
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 18, 2017
1 parent bf6f51e commit fb31f2a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ function monkeypatchExit () {
return original.call(this, code)
}
}(process.reallyExit)

process.exit = function (original) {
return function exit (code) {
code = onExitEvent(code)
return original.call(this, code)
}
}(process.exit)

process.on('exit', onExitEvent)
}

var didOnExitEvent = false
Expand All @@ -63,13 +72,14 @@ function onExitEvent (code) {
}

TAP.prototype.push = function push () {
// this resets push and pipe to standard values
this.pipe(process.stdout)

monkeypatchEpipe()
monkeypatchExit()
process.on('exit', onExitEvent)
process.on('uncaughtException', tap.threw)
return this.push.apply(tap, arguments)
process.on('uncaughtException', this.threw)

return this.push.apply(this, arguments)
}

TAP.prototype.onbail = function () {
Expand Down

0 comments on commit fb31f2a

Please sign in to comment.