This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
123 lines (103 loc) · 2.86 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
120
121
122
123
var Spinner = require('cli-spinner').Spinner;
var Table = require('cli-table');
var Colors = require('colors');
var spinner = new Spinner();
function startSpinner() {
if (global.process.argv.indexOf('ci') !== -1) {
spinner.start();
}
}
function stopSpinner() {
spinner.stop(true);
}
function MagentaReporter(out) {
this.out = out || process.stdout;
this.total = 0;
this.pass = 0;
this.fail = 0;
this.pending = 0;
this.duration = 0;
this.tests = {};
startSpinner();
}
MagentaReporter.prototype = {
report: function(prefix, data) {
this.total++;
if (!this.tests[prefix]) {
this.tests[prefix] = {
total: 0,
pass: 0,
fail: 0,
pending: 0,
duration: 0
};
}
this.tests[prefix].total++;
//The test has successfully ran.
if (!Number.isNaN(data.runDuration) && data.runDuration !== undefined) {
this.duration += data.runDuration;
this.tests[prefix].duration += data.runDuration;
if (data.passed) {
this.pass++;
this.tests[prefix].pass++;
} else {
stopSpinner();
this.fail++;
this.tests[prefix].fail++;
this.out.write((data.name + ': failed to pass in ' + prefix + '\n').underline.red);
if (data.error) {
this.out.write('| ' + data.error.message + '\n');
this.out.write('| ' + data.error.stack + '\n');
}
startSpinner();
}
} else {
this.pending++;
this.tests[prefix].pending++;
}
},
_addLastRow: function(table) {
var didPass,
name = 'All Sources';
if (this.fail === 0) {
didPass = 'P'.bold.green;
} else {
didPass = 'F'.bold.red;
name = name.red;
}
table.push([didPass, name, this.pass, this.fail, this.pending, this.total, this.duration + 'ms']);
return table;
},
finish: function() {
var table;
stopSpinner();
table = new Table({
head: ['P/F', 'Source', 'Pass'.bold.green, 'Fail'.bold.red, 'Pending'.bold.yellow, 'Total'.bold, 'Duration'],
colWidths: [5, 35, 10, 10, 10, 10, 10],
style: {
head: null
}
});
Object.keys(this.tests).forEach(function(k) {
var name = k.toString();
var pass = true;
if (this.tests[k].fail > 0) {
name = (name).red;
pass = false;
}
table.push([
pass ? 'P'.bold.green : 'F'.bold.red,
name,
this.tests[k].pass ? this.tests[k].pass.toString() : '0',
this.tests[k].fail ? this.tests[k].fail.toString() : '0',
this.tests[k].pending ? this.tests[k].pending.toString() : '0',
this.tests[k].total ? this.tests[k].total.toString() : '0',
this.tests[k].duration + "ms"
]);
}.bind(this));
table = this._addLastRow(table);
this.out.write(table.toString());
this.out.write('\n');
}
};
module.exports = MagentaReporter;