71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
|
"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]
|
||
|
};
|