Skip to content

Commit

Permalink
Handle unhandledRejection as a root TAP error
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 18, 2017
1 parent f9fa211 commit 29156e4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/tap.js
Expand Up @@ -78,6 +78,9 @@ TAP.prototype.push = function push () {
monkeypatchEpipe()
monkeypatchExit()
process.on('uncaughtException', this.threw)
process.on('unhandledRejection', function (er) {
this.threw(er)
}.bind(this))

return this.push.apply(this, arguments)
}
Expand Down
9 changes: 9 additions & 0 deletions test/test/unhandled-rejection--bail--buffer.tap
@@ -0,0 +1,9 @@
TAP version 13
# this is fine
not ok 1 - 💩
---
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
...

Bail out! # 💩

9 changes: 9 additions & 0 deletions test/test/unhandled-rejection--bail.tap
@@ -0,0 +1,9 @@
TAP version 13
# this is fine
not ok 1 - 💩
---
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
...

Bail out! # 💩

11 changes: 11 additions & 0 deletions test/test/unhandled-rejection--buffer.tap
@@ -0,0 +1,11 @@
TAP version 13
# this is fine
not ok 1 - 💩
---
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
...

1..1
# failed 1 test
___/# time=[0-9.]+(ms)?/~~~

12 changes: 12 additions & 0 deletions test/test/unhandled-rejection.js
@@ -0,0 +1,12 @@
if (typeof Promise === 'undefined')
Promise = require('bluebird')

var tap = require('../..')
tap.comment('this is fine')

function Poo () {
// Initially set the loaded status to a rejected promise
this.dump = Promise.reject(new Error('💩'))
}

new Poo()
11 changes: 11 additions & 0 deletions test/test/unhandled-rejection.tap
@@ -0,0 +1,11 @@
TAP version 13
# this is fine
not ok 1 - 💩
---
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
...

1..1
# failed 1 test
___/# time=[0-9.]+(ms)?/~~~

0 comments on commit 29156e4

Please sign in to comment.