-
Notifications
You must be signed in to change notification settings - Fork 1
/
reporter.js
67 lines (57 loc) · 1.45 KB
/
reporter.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
;(function () {
var tape = require('tape');
var stream = tape.createStream({ objectMode: true });
stream.on('data', report);
var currentTest = null;
function skip(row) {
console.log(
'%c⦿ %c%s',
'color: DeepSkyblue;',
'color: DimGray;',
row.name
);
}
function ok(row) {
console.log(
'%c✔︎ %c%s',
'color: LimeGreen;',
'color: DimGray;',
row.name
);
}
function fail(row) {
var pattern = /node_modules\/tape/i;
var stack = row.error.stack
.split('\n')
.map(function (line) { return line.trim() })
.filter(function (_, i) { return i > 0 });
console.group(
'%c✘ %c%s',
'color: OrangeRed;',
'color: Black; background-color: Yellow; font-weight: normal;',
row.name
);
console.log('expected:', row.expected, 'actual:', row.actual);
console.groupCollapsed('%c%s', 'font-weight: normal;', 'stack trace')
stack.forEach(function (line) {
pattern.test(line) ?
console.log('%c%s', 'color: DimGray;', line) :
console.log('%c%s', 'color: Black; background-color: Yellow;', line);
});
console.groupEnd();
console.groupEnd();
}
function report(row) {
switch (row.type) {
case 'test':
console.group(row.name);
break;
case 'end':
console.groupEnd();
break;
case 'assert':
row.skip ? skip(row) : row.ok ? ok(row) : fail(row);
break;
}
}
})();