-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathsummary.js
49 lines (39 loc) · 1.22 KB
/
summary.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
'use strict';
const chalk = require('chalk');
const table = require('text-table');
const pluralize = function (word, count) {
const plural = count === 1 ? word : word + 's';
return plural;
};
module.exports = function (results) {
const errorColor = 'red';
const warningColor = 'yellow';
let errorCount = 0;
let fileCount = 0;
let failureCount = 0;
let passCount = 0;
let warningCount = 0;
results.forEach(function (result) {
const messages = result.messages;
if (messages.length === 0) {
passCount++;
} else {
failureCount++;
warningCount += result.warningCount;
errorCount += result.errorCount;
}
});
fileCount = passCount + failureCount;
const summaryLineArray = [
chalk.bold(fileCount + ' ' + pluralize('file', fileCount) + ' checked.'),
chalk.bold(passCount + ' passed.'),
chalk.bold(failureCount + ' failed.')
];
if (warningCount || errorCount) {
summaryLineArray.push(chalk[warningColor].bold(warningCount + ' ' + pluralize('warning', warningCount) + '.'));
summaryLineArray.push(chalk[errorColor].bold(errorCount + ' ' + pluralize('error', errorCount) + '.'));
}
return '\n' +
table([summaryLineArray]) +
'\n';
};