Skip to content

Commit 29156e4

Browse files
committed
Handle unhandledRejection as a root TAP error
1 parent f9fa211 commit 29156e4

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

lib/tap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ TAP.prototype.push = function push () {
7878
monkeypatchEpipe()
7979
monkeypatchExit()
8080
process.on('uncaughtException', this.threw)
81+
process.on('unhandledRejection', function (er) {
82+
this.threw(er)
83+
}.bind(this))
8184

8285
return this.push.apply(this, arguments)
8386
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TAP version 13
2+
# this is fine
3+
not ok 1 - 💩
4+
---
5+
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
6+
...
7+
8+
Bail out! # 💩
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TAP version 13
2+
# this is fine
3+
not ok 1 - 💩
4+
---
5+
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
6+
...
7+
8+
Bail out! # 💩
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TAP version 13
2+
# this is fine
3+
not ok 1 - 💩
4+
---
5+
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
6+
...
7+
8+
1..1
9+
# failed 1 test
10+
___/# time=[0-9.]+(ms)?/~~~
11+

test/test/unhandled-rejection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if (typeof Promise === 'undefined')
2+
Promise = require('bluebird')
3+
4+
var tap = require('../..')
5+
tap.comment('this is fine')
6+
7+
function Poo () {
8+
// Initially set the loaded status to a rejected promise
9+
this.dump = Promise.reject(new Error('💩'))
10+
}
11+
12+
new Poo()

test/test/unhandled-rejection.tap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TAP version 13
2+
# this is fine
3+
not ok 1 - 💩
4+
---
5+
{"at":{"column":30,"constructor":true,"file":"test/test/unhandled-rejection.js","line":9},"source":"this.dump = Promise.reject(new Error('💩'))\n","test":"TAP"}
6+
...
7+
8+
1..1
9+
# failed 1 test
10+
___/# time=[0-9.]+(ms)?/~~~
11+

0 commit comments

Comments
 (0)