-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
109 lines (91 loc) · 3.41 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
// inject karma runner baseReporter and config
TaserReporter.$inject = ['baseReporterDecorator', 'config', 'formatError'];
function TaserReporter(baseReporterDecorator, config, formatError) {
// extend the base reporter
baseReporterDecorator(this);
var taserReporter = config.taserReporter || function() {};
var browsers = {};
var errors = {};
// This is not a full list of events that can be listened for, only the set we currently care about
this.onRunStart = onRunStart.bind(this);
this.onBrowserStart = onBrowserStart.bind(this);
this.onBrowserError = onBrowserError.bind(this);
this.onBrowserComplete = onBrowserComplete.bind(this);
this.onSpecComplete = onSpecComplete.bind(this);
this.onRunComplete = onRunComplete.bind(this);
function onRunStart() {
browsers = {};
errors = {};
}
function makeBrowserRecord (id, name, fullName) {
if (errors[id] === undefined) {
errors[id] = [];
}
if (browsers[id] === undefined) {
browsers[id] = {
browser: {
name: name,
fullName: fullName
},
testResults: {
passed: [],
skipped: [],
failed: []
},
errors: errors[id]
};
}
}
function onBrowserError(browser, error) {
makeBrowserRecord(browser.id, browser.name, browser.fullName);
errors[browser.id] = errors[browser.id] || [];
errors[browser.id].push(betterFormatError(error));
}
function onBrowserStart(browser, error) {
makeBrowserRecord(browser.id, browser.name, browser.fullName);
}
function onBrowserComplete(browser) {
// This will get caught by `onBrowserError` in the new version of karma, but until then:
if (browser.lastResult.disconnected) {
makeBrowserRecord(browser.id, browser.name, browser.fullName);
errors[browser.id] = errors[browser.id] || [];
errors[browser.id].push('A test timed out after ' + browser.lastResult.totalTime + 'ms, likely due to an infinite loop or very high time complexity.');
}
}
function onSpecComplete(browser, testResult) {
var category;
// Set the test result category for this test
if( testResult.success ) {
category = 'passed';
}
else if( testResult.skipped || testResult.ignored ) {
category = 'skipped';
}
else {
category = 'failed';
}
if (testResult.log instanceof Array && testResult.log.length > 0) {
testResult.log = testResult.log.map(betterFormatError);
}
// Add the test result to this browsers test results in its proper category
browsers[browser.id].testResults[category].push(testResult);
}
function onRunComplete(browser, result) {
var reports = [];
var browser;
for( browser in browsers ) {
reports.push(browsers[browser]);
}
taserReporter(reports);
}
function betterFormatError(error) {
if (error.match(/Maximum call stack size exceeded./)) {
return 'Maximum call stack size exceeded.';
}
return formatError(error);
}
}
// PUBLISH DI MODULE
module.exports = {
'reporter:taser': ['type', TaserReporter]
};