/
dot_reporter.js
99 lines (90 loc) · 2.31 KB
/
dot_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
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
'use strict';
var indent = require('../strutils').indent;
var printf = require('printf');
function DotReporter(silent, out) {
this.out = out || process.stdout;
this.silent = silent;
this.stoppedOnError = null;
this.id = 1;
this.total = 0;
this.pass = 0;
this.skipped = 0;
this.results = [];
this.startTime = new Date();
this.endTime = null;
this.currentLineChars = 0;
this.maxLineChars = Math.min(this.out.columns || 65, 65) - 5;
this.out.write('\n');
this.out.write(' ');
}
DotReporter.prototype = {
report: function(prefix, data) {
this.results.push({
launcher: prefix,
result: data
});
this.display(prefix, data);
this.total++;
if (data.skipped) {
this.skipped++;
} else if (data.passed) {
this.pass++;
}
},
display: function(prefix, result) {
if (this.silent) {
return;
}
if (this.currentLineChars > this.maxLineChars) {
this.currentLineChars = 0;
this.out.write('\n ');
}
if (result.passed) {
this.out.write('.');
} else if (result.skipped) {
this.out.write('*');
} else {
this.out.write('F');
}
this.currentLineChars += 1;
},
finish: function() {
if (this.silent) {
return;
}
this.endTime = new Date();
this.out.write('\n\n');
this.out.write(this.summaryDisplay());
this.out.write('\n\n');
this.displayErrors();
},
displayErrors: function() {
this.results.forEach(function(data, idx) {
var result = data.result;
var error = result.error;
if (!error) {
return;
}
printf(this.out, '%*d) [%s] %s\n', idx + 1, 3, data.launcher, result.name);
if (error.message) {
printf(this.out, ' %s\n', error.message);
}
if ('expected' in error && 'actual' in error) {
printf(this.out, '\n' +
' expected: %O\n' +
' actual: %O\n', error.expected, error.actual);
}
if (error.stack) {
printf(this.out, '\n%s', indent(error.stack, 5));
}
this.out.write('\n\n');
}, this);
},
summaryDisplay: function() {
return printf(' %d tests complete (%d ms)', this.total, this.duration());
},
duration: function() {
return Math.round((this.endTime - this.startTime));
}
};
module.exports = DotReporter;