-
Notifications
You must be signed in to change notification settings - Fork 16
/
blue-tape.js
51 lines (45 loc) · 1013 Bytes
/
blue-tape.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var Test = require('tape/lib/test')
function checkPromise (p) {
return p && p.then && typeof p.then === 'function'
}
Test.prototype.run = function () {
if (this._skip) {
return this.end()
}
this.emit('prerun')
try {
var p = this._cb && this._cb(this)
var isPromise = checkPromise(p)
var self = this
if (isPromise) {
p.then(function () {
self.end()
}, function (err) {
err ? self.error(err) : self.fail(err)
self.end()
})
}
} catch (err) {
if (err) {
this.error(err)
} else {
this.fail(err)
}
this.end()
return
}
this.emit('run')
}
function noop() {}
Test.prototype.shouldFail =
Test.prototype.shouldReject =
function (promise, expected, message, extra) {
var self = this
return promise.then(function () {
self.throws(noop, expected, message, extra)
}, function (err) {
function f() {throw err}
self.throws(f, expected, message, extra)
})
}
module.exports = require('tape')