This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
test-result-formatting.js
94 lines (74 loc) · 2.47 KB
/
test-result-formatting.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
'use strict';
var chalk = require('chalk');
var _ = require('underscore');
var utils = require('./utils');
var formatSuccessLine = function(success) {
return success.name + '#' + success.methodName + ' took ' + success.time
};
var formatSuccesses = function(testResult) {
var successes = utils.ensureArray(testResult.successes);
if (!successes.length) {
return [];
}
return ['Successes:'].concat(_.map(
successes, _.compose(chalk.green, formatSuccessLine)
));
};
var formatFailure = function(failure) {
return [
chalk.red(failure['name'] + '#' + failure['methodName'] + ' took ' + failure['time']),
' - ' + failure['message'],
' - ' + failure['stackTrace']
];
};
var formatFailures = function(testResult) {
var failures = utils.ensureArray(testResult.failures);
if (!failures.length) {
return [];
}
return _.flatten(['Failures:'].concat(_.map(failures, function(failure) {
return formatFailure(failure);
})));
};
var formatOverview = function(testResult) {
var successCount = utils.ensureArray(testResult.successes).length;
var failureCount = utils.ensureArray(testResult.failures).length;
var testCount = successCount + failureCount;
var testCountText = testCount + ' method' + (testCount === 1 ? '' : 's');
var failureCountText = failureCount + ' failure' + (failureCount === 1 ? '' : 's');
return [testCountText + ', ' + failureCountText];
};
var formatCodeCoverageWarnings = function(testResult) {
var warnings = utils.ensureArray(testResult.codeCoverageWarnings);
if (!warnings.length) {
return [];
}
return ['Code Coverage Warnings:'].concat(warnings.map(function(warning) {
var name = warning.name;
var prefix = '';
if (_.isString(name)) {
prefix = name + ': ';
}
return prefix + warning.message;
}));
};
var formatComponentFailures = function(deployDetails) {
var componentFailures = utils.ensureArray(deployDetails.componentFailures);
if (!componentFailures.length) {
return [];
}
return ['Component Failures:'].concat(componentFailures.map(function(f) {
if (f.fullName && f.componentType) {
return ' - ' + f.problemType + " in " + f.componentType + " component '" + f.fullName + "': " + f.problem;
} else {
return ' - ' + f.problemType + " in file '" + f.fileName + "': " + f.problem;
}
}));
};
module.exports = {
formatSuccesses: formatSuccesses,
formatFailures: formatFailures,
formatOverview: formatOverview,
formatCodeCoverageWarnings: formatCodeCoverageWarnings,
formatComponentFailures: formatComponentFailures
};