-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
56 lines (49 loc) · 1.27 KB
/
runner.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
52
53
54
55
56
'use strict'
var each = require('each-promise')
var Bluebird = require('bluebird')
function Runner () {
this._tests = []
}
Runner.prototype.addTest = function addTest (title, fn) {
function wrapper () {
var promise = new Bluebird(function (resolve) {
resolve(fn())
})
return promise
}
wrapper.title = title
this._tests.push(wrapper)
}
Runner.prototype.runTests = function runTests (show) {
var titles = []
return each.serial(this._tests, {
settle: true,
flat: false,
Promise: Bluebird,
beforeEach: function (item) {
titles[item.index] = item.value.title
},
afterEach: function (item) {
/* istanbul ignore next */
if (!show) return
/* istanbul ignore next */
if (item.reason) {
console.error('not ok', item.index + 1, titles[item.index])
console.error(item.reason.stack)
return
}
/* istanbul ignore next */
console.log('ok', item.index + 1, titles[item.index])
}
}).then(function (res) {
var result = res.map(function (item) {
item.title = titles[item.index]
/* istanbul ignore next */
return item.reason ? item : false
})
result = result.filter(Boolean)
result.tests = res.length
return result
})
}
module.exports = Runner