/
HTMLReporter.js
78 lines (53 loc) · 1.73 KB
/
HTMLReporter.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
"use strict";
var Reporter = require('./Reporter');
var prime = require('prime');
var HTMLReporter = prime({
inherits: Reporter,
constructor: function(object){
HTMLReporter.parent.constructor(object);
// TODO would be cool to use some nicer templating solution for this
this.head = '' +
'<!DOCTYPE html>\n' +
'<html>\n<head>\n' +
'<meta charset="utf-8">\n' +
'<title>Coverate Results</title>\n' +
'<style>\n' +
' .error { background: #F8D5D8 }\n' +
' .count { font-weight: bold; border-radius: 3px }\n' +
' .pass .count { background: #BFFFBF;}' +
' .error .count { background: #F8D5D8; color: red}' +
'</style>\n' +
'</head>\n<body>\n';
this.tail = '\n</body>\n</html>';
},
report: function(){
var result = this.head;
for (var file in this.object){
var fileReporter = new HTMLFileReporter(this.object[file]);
var fileReport = fileReporter.report();
var percentage = fileReporter.pass / fileReporter.total * 100;
this.error += fileReporter.error;
this.pass += fileReporter.pass;
this.total += fileReporter.total;
result += '<h1>' + file + ' (' + Math.round(percentage) + '%)</h1>\n\n';
result += '<pre>' + fileReport + '</pre>';
}
return result + this.tail;
}
});
var HTMLFileReporter = prime({
inherits: Reporter.FileReporter,
constructor: function(object){
var open = '<span class="{class}" data-count="{count}"><span class="count">{count}</span>';
var close = '</span>';
HTMLFileReporter.parent.constructor(object, open, close);
},
generateOpen: function(count){
return this.substitute(this.open, {
'count': count,
'class': count ? 'pass' : 'error'
});
}
});
HTMLReporter.FileReporter = HTMLFileReporter;
module.exports = HTMLReporter;