-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
59 lines (48 loc) · 1.26 KB
/
index.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
57
58
59
var parser = require('tap-parser')
var through = require('through2')
var duplexer = require('duplexer')
var hirestime = require('hirestime')
var prettyms = require('pretty-ms')
var chalk = require('chalk')
module.exports = function() {
var tap = parser()
var out = through()
var stream = duplexer(tap, out)
function output(str) {
out.push(' ' + str)
out.push('\n')
}
function format(total, time) {
var word = (total > 1) ? 'tests' : 'test'
return total + ' ' + word + ' complete (' + time + ')'
}
var timer = hirestime()
var errors = []
var current = null
tap.on('comment', function(res) {
current = '\n' + ' ' + res
})
tap.on('assert', function(res) {
var assert = current + ' ' + res.name
if (!res.ok) errors.push(chalk.white(assert))
})
tap.on('extra', function(res) {
if (res !== '') errors.push(chalk.gray(res))
})
tap.on('results', function(res) {
var count = res.asserts.length
var time = prettyms(timer())
out.push('\n')
if (errors.length) {
output(chalk.red(format(count, time)))
errors.forEach(function(error) {
output(error)
})
} else {
output(chalk.green(format(count, time)))
}
out.push('\n')
})
stream.errors = errors
return stream
}