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

@ -13,5 +13,7 @@ html
body
div#report
a( href="index.html" ) h5ai #{pkg.version} test suite
div.stats
div.progress
div#mocha-overlay
div#mocha

View file

@ -36,6 +36,21 @@
&.fail {
background: @col-red-500;
}
.stats {
display: block;
position: absolute;
right: 8px;
top: 0;
cursor: pointer;
}
.progress {
display: block;
position: absolute;
right: 0;
bottom: 0;
height: 100%;
background: rgba(255,255,255,0.2);
}
}
#mocha-overlay {
@ -191,38 +206,35 @@
}
#mocha-stats {
position: fixed;
top: 40px;
right: 20px;
margin: 0;
color: @col-grey-800;
z-index: 1;
font-size: 13px;
display: none;
// position: fixed;
// top: 40px;
// right: 20px;
// margin: 0;
// color: @col-grey-800;
// z-index: 1;
// font-size: 13px;
em {
font-style: normal;
font-size: 14px;
}
a {
text-decoration: none;
color: inherit;
}
li {
display: inline-block;
margin: 0 5px;
list-style: none;
padding-top: 11px;
}
canvas {
width: 40px;
height: 40px;
}
.progress {
float: right;
padding-top: 0;
}
.passes, .failures {
cursor: pointer;
}
// em {
// font-style: normal;
// font-size: 14px;
// }
// a {
// text-decoration: none;
// color: inherit;
// }
// li {
// display: inline-block;
// margin: 0 5px;
// list-style: none;
// padding-top: 11px;
// }
// canvas {
// width: 40px;
// height: 40px;
// }
// .progress {
// float: right;
// padding-top: 0;
// }
}

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 || {};