forked from HuddleEng/PhantomFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard-logger.js
158 lines (125 loc) · 4.25 KB
/
dashboard-logger.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var _ = require('lodash');
function logWithLogger(args, logger){
_.toArray(args).forEach(function (arg) {
var lines = arg.split('\n');
logger.log(_.head(lines));
_.tail(lines).forEach(function (line) {
logger.log(' ' + line);
});
});
}
function log(){
logWithLogger(arguments, cliLog);
}
function errorLog(){
logWithLogger(arguments, cliErrorLog);
}
var cliLog, cliErrorLog, table, box, gauge, screen, confirmation;
var tableHeaders = ['Test file', 'Status'];
function updateTableAndStats(statuses, passCount, failCount, numSucceeded, numFailed, numTests){
var dataArray = [];
var nowDate = new Date().getTime();
_.forEach(statuses, function(testData, fileName) {
var status = testData.testStatus;
var row = [];
if(status === 'PENDING'){
row = [fileName.blue, status.blue];
} else if (status === 'RUNNING') {
row = [fileName.yellow, status.yellow];
} else if (status === 'SUCCESS') {
row = [fileName.green, status.green];
} else if (status === 'FAIL') {
row = [fileName.red, status.red];
} else {
row = [fileName, status];
}
if(status === 'PENDING'){
row.push('');
} else {
row.push(((testData.endTime === Infinity ? nowDate : testData.endTime) - testData.startedTime)/1000 + 's');
}
row.push(testData.numPasses + ' passes', testData.numFails + ' fails');
dataArray.push(row);
});
table.setData({ headers: tableHeaders, data: dataArray.reverse()});
box.setContent(passCount + ' successful and ' + failCount + ' failed assertions so far.');
gauge.setStack([{percent: Math.ceil( numSucceeded / numTests * 100), stroke: 'green'}, {percent: Math.ceil( numFailed / numTests * 100), stroke: 'red'}]);
_.throttle(screen.render, 500);
}
module.exports = {
init: function () {
var blessed = require('blessed')
, contrib = require('blessed-contrib');
screen = blessed.screen();
var grid = new contrib.grid({rows: 4, cols: 2, screen: screen});
gauge = grid.set(0, 0, 1, 1, contrib.gauge,
{
label: 'Completed tests'
});
gauge.setStack([0,0]);
box = grid.set(1, 0, 1, 1, blessed.box, {
content: ' '
});
cliLog = grid.set(2, 0, 2, 1, contrib.log, {
fg: "green",
label: 'Output',
height: "50%",
tags: true,
border: {type: "line", fg: "cyan"} });
cliErrorLog = grid.set(2, 1, 2, 1, contrib.log, {
fg: "green",
label: 'Error Log',
height: "50%",
tags: true,
border: {type: "line", fg: "cyan"} });
table = grid.set(0,1,2,1, contrib.table, {
keys: true,
fg: 'white',
selectedFg: 'white',
selectedBg: 'blue',
interactive: true,
label: 'Test summary',
width: '100%',
height: '100%',
border: {type: "line", fg: "cyan"},
columnSpacing: 2,
columnWidth: [50, 12, 12, 12, 12]
});
table.focus();
table.setData({ headers: tableHeaders, data: [['', '']]});
confirmation = blessed.message({
top: 'center',
left: 'center',
width: 'shrink',
height: 'shrink',
tags: true,
hidden: true,
border: {
type: 'line'
},
style: {
fg: 'white',
bg: 'magenta',
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(confirmation);
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
screen.render();
},
log: log,
error: errorLog,
update: updateTableAndStats,
finish: function () {
confirmation.display('All tests have completed. Hit enter to dismiss this message. Hit q or C-c to quit.', 0);
confirmation.focus();
screen.render();
}
};