2019-08-19 11:53:58 -04:00
|
|
|
"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);
|
|
|
|
}
|
|
|
|
|
2020-09-22 23:18:45 -04:00
|
|
|
let dummyStarted = false;
|
2019-08-19 11:53:58 -04:00
|
|
|
this.onRunComplete = function (browsers, results) {
|
|
|
|
if (lastSuite !== null) {
|
|
|
|
runner.emit('suite end');
|
|
|
|
lastSuite = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// end the dummy suite for total test count
|
2020-09-22 23:18:45 -04:00
|
|
|
if (dummyStarted) {
|
|
|
|
runner.emit('suite end');
|
|
|
|
}
|
2019-08-19 11:53:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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', {});
|
2020-09-22 23:18:45 -04:00
|
|
|
dummyStarted = true;
|
2019-08-19 11:53:58 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// end previous suite
|
|
|
|
runner.emit('suite end');
|
|
|
|
}
|
|
|
|
|
|
|
|
runner.emit('suite', { title: result.suite });
|
|
|
|
lastSuite = result.suite[0];
|
|
|
|
}
|
|
|
|
|
2020-09-05 01:14:25 -04:00
|
|
|
runner.emit('test', {
|
|
|
|
_currentRetry: 0
|
|
|
|
});
|
2019-08-19 11:53:58 -04:00
|
|
|
|
|
|
|
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]
|
|
|
|
};
|