h5ai/test/util/mocha.js

84 lines
2 KiB
JavaScript
Raw Normal View History

2015-04-22 18:08:43 -04:00
(function () {
'use strict';
2015-04-23 17:52:59 -04:00
function onEnd() {
2015-04-26 14:02:23 -04:00
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();
});
}
2015-04-24 09:34:06 -04:00
$('#report').addClass(failed ? 'fail' : 'pass');
2015-04-26 14:02:23 -04:00
$('#report .progress').hide();
$('#report .stats').text(stats);
2015-04-22 18:08:43 -04:00
$('#mocha-overlay .suite').each(function () {
var $suite = $(this);
var tests = $suite.find('.test').length;
var passed = $suite.find('.test.pass').length;
var failed = tests - passed;
var $header = $suite.find('> h1 a');
var $count = $('<span class="count"><span class="passed">' + passed + '</span><span class="failed">' + failed + '</span></span>');
if (!failed) {
$count.find('.failed').remove();
}
$suite.addClass(tests === passed ? 'pass' : 'fail');
$header.append($count);
});
$('#mocha-overlay code').each(function () {
var $code = $(this);
$code.text($code.text().trim().replace(/;\n\s*/g, ';\n'));
});
2015-04-26 14:02:23 -04:00
}
2015-04-24 09:17:54 -04:00
2015-04-26 14:02:23 -04:00
function onTest() {
2015-04-24 09:17:54 -04:00
2015-04-26 14:02:23 -04:00
var runner = this;
var complete = runner.stats.tests;
var total = runner.total;
var percent = 100.0 - 100.0 * complete / total;
2015-04-24 09:34:06 -04:00
2015-04-26 14:02:23 -04:00
if (runner.stats.failures) {
$('#report').addClass('fail');
2015-04-24 09:34:06 -04:00
}
2015-04-26 14:02:23 -04:00
$('#report .progress').css('width', percent + '%');
2015-04-22 18:08:43 -04:00
}
function setupMocha() {
window.assert = chai.assert;
mocha.setup('bdd');
}
function runMocha() {
2015-04-26 14:02:23 -04:00
mocha.run().on('test', onTest).on('end', onEnd);
2015-04-22 18:08:43 -04:00
}
window.util = window.util || {};
window.util.setupMocha = setupMocha;
window.util.runMocha = runMocha;
}());