forked from guyius/karma-simple-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (55 loc) · 1.94 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
'use strict';
var SpecReporter = function (baseReporterDecorator) {
baseReporterDecorator(this);
require('colors');
var failures = {tests: [], suites: {}};
var TOTAL_SUCCESS = '\n' + 'TOTAL: %d SUCCESS'.green;
var TOTAL_FAILED = '\n' + 'TOTAL: %d FAILED'.red + ', ' + '%d SUCCESS'.green;
this.onRunComplete = function (browsers, results) {
if (browsers.length >= 1 && !results.disconnected && !results.error) {
if (!results.failed) {
this.write(TOTAL_SUCCESS, results.success);
} else {
this.write(TOTAL_FAILED, results.failed, results.success);
this.write('\n\n') ;
this._logFinalErrors(failures);
this.write('\n\n') ;
}
}
this.write('\n');
failures = {tests: [], suites: {}};
};
this._logFinalErrors = function (failures, prefix) {
prefix = prefix || '';
failures.tests.forEach(function (failure) {
this.write((prefix + 'IT => ' + failure.description + '\n').cyan);
failure.log.forEach(function (log) {
this.write((prefix + ' ERROR => ' + log + '\n').red);
}, this);
}, this);
Object.keys(failures.suites).forEach(function (suite) {
this.write((prefix + 'DESCRIBE => ' + fromKey(suite) + '\n').yellow);
this._logFinalErrors(failures.suites[suite], prefix + ' ');
}, this);
};
this.onSpecComplete = function (browser, result) {
if (result.success === false) {
var current = failures;
result.suite.forEach(function (suite) {
current = current.suites[toKey(suite)] = current.suites[toKey(suite)] || {tests: [], suites: {}};
}, this);
current.tests.push(result);
}
};
var KEY_PREFIX = '$$';
function toKey(forValue) {
return KEY_PREFIX + forValue;
}
function fromKey(forValue) {
return forValue.substring(KEY_PREFIX.length);
}
};
SpecReporter.$inject = ['baseReporterDecorator'];
module.exports = {
'reporter:karmaSimpleReporter': ['type', SpecReporter]
};