Update test runner.

This commit is contained in:
Lars Jung 2015-04-26 20:02:23 +02:00
parent 63fe57731e
commit 21c976bb3d
3 changed files with 77 additions and 49 deletions

View file

@ -3,9 +3,28 @@
function onEnd() {
var failed = $('.test.fail').length > 0;
var runner = this;
var failed = runner.stats.failures > 0;
var stats = (runner.stats.duration / 1000.0).toFixed(2) + 's';
if (failed) {
var onlyFailures = false;
$('#report .stats').on('click', function (ev) {
onlyFailures = !onlyFailures;
if (onlyFailures) {
$('.suite, .test').hide();
$('.suite.fail, .test.fail').show();
} else {
$('.suite, .test').show();
}
ev.stopImmediatePropagation();
});
}
$('#report').addClass(failed ? 'fail' : 'pass');
$('#report .progress').hide();
$('#report .stats').text(stats);
$('#mocha-overlay .suite').each(function () {
@ -31,24 +50,19 @@ function onEnd() {
var $code = $(this);
$code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
});
}
$('#mocha-stats .passes a').replaceWith('<span>passes:</span>');
$('#mocha-stats .failures a').replaceWith('<span>failures:</span>');
function onTest() {
if (failed) {
var onlyFailures = false;
$('#mocha-stats .failures').on('click', function (ev) {
var runner = this;
var complete = runner.stats.tests;
var total = runner.total;
var percent = 100.0 - 100.0 * complete / total;
onlyFailures = !onlyFailures;
if (onlyFailures) {
$('.suite, .test').hide();
$('.suite.fail, .test.fail').show();
} else {
$('.suite, .test').show();
}
ev.stopImmediatePropagation();
});
if (runner.stats.failures) {
$('#report').addClass('fail');
}
$('#report .progress').css('width', percent + '%');
}
function setupMocha() {
@ -59,7 +73,7 @@ function setupMocha() {
function runMocha() {
mocha.run().on('end', onEnd);
mocha.run().on('test', onTest).on('end', onEnd);
}
window.util = window.util || {};