-
Notifications
You must be signed in to change notification settings - Fork 24
/
karma-reporter.js
70 lines (56 loc) · 1.48 KB
/
karma-reporter.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
"use strict";
const Reporter = require('./reporter')
const EventEmitter = require('events');
const KarmaReporter = function () {
const runner = new EventEmitter();
const reporter = new Reporter(runner);
let lastSuite = null;
// capture console logs
this.onBrowserLog = function (browser, log, type) {
console.log('\x1b[36m%s\x1b[0m', log);
}
this.onRunComplete = function (browsers, results) {
if (lastSuite !== null) {
runner.emit('suite end');
lastSuite = null;
}
// end the dummy suite for total test count
runner.emit('suite end');
}
this.onSpecComplete = function (browser, result) {
if (result.suite[0] !== lastSuite) {
if (lastSuite === null) {
// this is the first test, start a dummy suite to track total test count
runner.emit('suite', {});
}
else {
// end previous suite
runner.emit('suite end');
}
runner.emit('suite', { title: result.suite });
lastSuite = result.suite[0];
}
runner.emit('test');
if (result.skipped) {
runner.emit('skipped');
}
else if (result.success) {
runner.emit('pass');
}
else {
const test = {
title: result.description,
};
const error = {
browser: browser.name,
suite: result.suite,
test: result.description,
log: result.log
}
runner.emit('fail', test, error);
}
}
}
module.exports = {
'reporter:karma': ['type', KarmaReporter]
};