Skip to content

Commit

Permalink
Expose the uncaughtException handler better
Browse files Browse the repository at this point in the history
Partly addresses #475, albeit via a somewhat hacky workaround.
  • Loading branch information
isaacs committed Jan 22, 2019
1 parent cf8a2e1 commit f2f0746
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/tap.js
Expand Up @@ -66,7 +66,7 @@ class TAP extends Test {
patchProcess () {
monkeypatchEpipe()
monkeypatchExit()
process.on('uncaughtException', this.threw)
process.on('uncaughtException', er => this.threw(er))
process.on('unhandledRejection', er => this.threw(er))
}

Expand Down
17 changes: 10 additions & 7 deletions tap-snapshots/test-tap.js-TAP.test.js
Expand Up @@ -213,31 +213,34 @@ Error: poop
`

exports[`test/tap.js TAP process.exitCode polyfill > exit status 1`] = `
exports[`test/tap.js TAP uncaught exception > exit status 1`] = `
{ code: 1, signal: null }
`

exports[`test/tap.js TAP process.exitCode polyfill > stdout 1`] = `
exports[`test/tap.js TAP uncaught exception > stdout 1`] = `
TAP version 13
not ok 1 - v0.10.420
ok 1 - this is fine
ok 2 - i am sure things are ok
not ok 3 - poop
---
at:
line: #
column: #
file: test/tap.js
source: |
t.fail(process.version)
setTimeout(() => { throw new Error('poop') })
stack: |
{STACK}
test: TAP
...
1..1
# failed 1 test
1..3
# failed 1 of 3 tests
# {time}
`

exports[`test/tap.js TAP process.exitCode polyfill > stderr 1`] = `
exports[`test/tap.js TAP uncaught exception > stderr 1`] = `
`

Expand Down
5 changes: 5 additions & 0 deletions test/tap.js
Expand Up @@ -38,6 +38,11 @@ const cases = {
t.on('teardown', () => { throw new Error('poop') })
t.pass('x')
},
'uncaught exception': t => {
t.pass('this is fine')
setTimeout(() => { throw new Error('poop') })
t.pass('i am sure things are ok')
},
'TAP_DEBUG=1': [
() => process.env.TAP_DEBUG = '1',
t => t.comment('this is fine')
Expand Down

0 comments on commit f2f0746

Please sign in to comment.