-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
119 lines (94 loc) · 2.87 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var format = require('chalk')
var Rx = require('rx')
var R = require('ramda')
var diffChars = require('diff').diffChars
var figures = require('figures')
var indent = R.pipe(pad, pad)
var errorIndent = R.pipe(indent, pad)
var addExtraIndent = R.pipe(R.defaultTo(0), R.repeat(' '), R.join(''))
var formatDiff = R.pipe(
diffChars,
R.map(function (part) {
var color = part.added ? 'bgGreen' : part.removed ? 'bgRed' : 'white'
return format[color](part.value)
}),
R.join('')
)
var exports = module.exports = function (input$) {
var output$ = new Rx.Subject()
// Failure Title
input$.failingAssertions$
.count()
.forEach(function (failureCount) {
if (failureCount < 1) {
return output$.onCompleted()
}
var past = failureCount === 1 ? 'was' : 'were'
var plural = failureCount === 1 ? 'failure' : 'failures'
var title = [
format.red.bold('Failed Tests:'),
'There ' + past + ' ' + format.red.bold(failureCount) + ' ' + plural,
].join(' ')
output$.onNext(pad(title))
output$.onNext('')
})
// Output failures
Rx.Observable
.merge(
input$.tests$,
input$.failingAssertions$
)
.scan(function (accum, item) {
if (item.type === 'test') {
accum[item.testNumber] = {
test: item,
assertions: []
}
}
else {
accum[item.testNumber].assertions.push(item)
}
return accum
}, {})
.takeLast(1)
.forEach(function (group) {
Object.keys(group)
.filter(function (number) {return group[number].assertions.length > 0})
.map(function (number) {return group[number]})
.forEach(function (set) {
output$.onNext(pad(pad(set.test.title)))
set.assertions
.forEach(function (assertion) {
var line = pad(pad(pad([
format.red(figures.cross + ' ' + assertion.title),
'\n',
pad(''),
'\n'
].join(' '))))
output$.onNext(formatAssertionError(assertion, 2))
})
output$.onNext('')
})
output$.onCompleted()
})
return output$
}
exports.formatAssertionError = formatAssertionError
function formatAssertionError (line, extraIndent) {
var diffs = formatDiff(String(line.diagnostic.expected), String(line.diagnostic.actual))
var output = []
output.push(indent(format.red.bold(figures.cross + ' ' + line.title)))
output.push(indent(format.dim(' at ') + format.dim(line.diagnostic.at)))
output.push('')
output.push(errorIndent(format.bgGreen('actual') + ' ' + format.bgRed('expected')))
output.push('')
output.push(errorIndent(diffs))
output.push('')
return output
.map(function (input) {return addExtraIndent(extraIndent) + input})
.join('\n')
}
function pad (str) {
str = str || ''
return ' ' + str
}