2018-08-03 00:10:38 +03:00
|
|
|
|
|
|
|
function getTime() {
|
|
|
|
return (new Date()).getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDelta(t0) {
|
|
|
|
var ds = parseInt((getTime() - t0) / 1000);
|
|
|
|
var minutes = parseInt(ds / 60);
|
|
|
|
var seconds = String(parseInt(ds) % 60);
|
|
|
|
while (seconds.length < 2) { seconds = '0' + seconds; }
|
|
|
|
return '(' + minutes + ':' + seconds + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
function Reporter(runner) {
|
|
|
|
var self = this;
|
|
|
|
var suites = [];
|
|
|
|
|
2018-08-03 00:56:50 +03:00
|
|
|
var lastOutput = getTime();
|
|
|
|
|
2018-08-03 00:10:38 +03:00
|
|
|
function getIndent() {
|
|
|
|
var result = '';
|
|
|
|
for (var i = 0; i < suites.length; i++) { result += ' '; }
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:56:50 +03:00
|
|
|
function log(message) {
|
|
|
|
if (!message) { message = ''; }
|
|
|
|
var indent = getIndent();
|
|
|
|
console.log(indent + message);
|
|
|
|
lastOutput = getTime();
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:10:38 +03:00
|
|
|
runner.on('suite', function(suite) {
|
|
|
|
if (!suite.title) {
|
2018-08-03 00:56:50 +03:00
|
|
|
log('Testing: Found ' + suite.suites.length + ' test suites');
|
2018-08-03 00:10:38 +03:00
|
|
|
} else {
|
|
|
|
var filename = (suite.file || '').split('/').pop();
|
|
|
|
if (filename) { filename = ' (' + filename + ')'; }
|
2018-08-03 00:56:50 +03:00
|
|
|
log('Test Suite: ' + suite.title + filename);
|
2018-08-03 00:10:38 +03:00
|
|
|
}
|
|
|
|
suites.push(suite);
|
|
|
|
suite._t0 = getTime();
|
|
|
|
suite._countFail = 0;
|
|
|
|
suite._countPass = 0;
|
|
|
|
suite._countTotal = 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('suite end', function() {
|
|
|
|
var suite = suites.pop();
|
2018-08-03 00:56:50 +03:00
|
|
|
log(' Total Tests: ' + suite._countPass + '/' + suite._countTotal + ' passed ' + getDelta(suite._t0));
|
|
|
|
log();
|
2018-08-03 00:10:38 +03:00
|
|
|
if (suites.length > 0) {
|
|
|
|
var currentSuite = suites[suites.length - 1];
|
|
|
|
currentSuite._countFail += suite._countFail;
|
|
|
|
currentSuite._countPass += suite._countPass;
|
|
|
|
currentSuite._countTotal += suite._countTotal;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('test', function(test) {
|
|
|
|
var currentSuite = suites[suites.length - 1];
|
2018-08-03 00:56:50 +03:00
|
|
|
if (((getTime() - lastOutput) / 1000) > 60) {
|
|
|
|
log('[ Still running suite - test #' + currentSuite._countTotal + ' ]');
|
|
|
|
lastOutput = getTime();
|
|
|
|
}
|
2018-08-03 00:10:38 +03:00
|
|
|
currentSuite._countTotal++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('fail', function(test, error) {
|
|
|
|
var currentSuite = suites[suites.length - 1];
|
|
|
|
currentSuite._countFail++;
|
|
|
|
|
|
|
|
var countFail = currentSuite._countFail;
|
|
|
|
var indent = getIndent();
|
|
|
|
|
|
|
|
if (countFail > 100) {
|
|
|
|
if (countFail === 101) {
|
2018-08-03 00:56:50 +03:00
|
|
|
log('[ Over 100 errors; skipping remaining suite output ]');
|
2018-08-03 00:10:38 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (countFail > 25) {
|
2018-08-03 00:56:50 +03:00
|
|
|
log('Failure: ' + test.title + ' (too many errors; skipping dump)');
|
2018-08-03 00:10:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-03 00:56:50 +03:00
|
|
|
log('Failure: ' + test.title);
|
2018-08-03 00:10:38 +03:00
|
|
|
error.toString().split('\n').forEach(function(line) {
|
2018-08-03 00:56:50 +03:00
|
|
|
log(' ' + line);
|
2018-08-03 00:10:38 +03:00
|
|
|
});
|
|
|
|
Object.keys(error).forEach(function(key) {
|
2018-08-03 00:56:50 +03:00
|
|
|
log(' ' + key + ': ' + error[key]);
|
2018-08-03 00:10:38 +03:00
|
|
|
});
|
2018-08-03 00:56:50 +03:00
|
|
|
if (error.stack) {
|
|
|
|
log("Stack Trace:");
|
|
|
|
error.stack.split('\n').forEach(function(line) {
|
|
|
|
log(' ' + line);
|
|
|
|
});
|
|
|
|
}
|
2018-08-03 00:10:38 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
runner.on('pass', function(test) {
|
|
|
|
var currentSuite = suites[suites.length - 1];
|
|
|
|
currentSuite._countPass++;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Reporter;
|