diff --git a/test/util/mocha.js b/test/util/mocha.js index 47a75643..a3490fbb 100644 --- a/test/util/mocha.js +++ b/test/util/mocha.js @@ -1,63 +1,68 @@ (function () { 'use strict'; +var showOnlyFailures = false; + +function toggleFailureFilter(ev) { + + ev.stopImmediatePropagation(); + + showOnlyFailures = !showOnlyFailures; + if (showOnlyFailures) { + $('.suite, .test').hide(); + $('.suite.fail, .test.fail').show(); + } else { + $('.suite, .test').show(); + } +} + +function addSuiteStats() { + + 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 = $('' + passed + '' + failed + ''); + + if (!failed) { + $count.find('.failed').remove(); + } + + $suite.addClass(tests === passed ? 'pass' : 'fail'); + $header.append($count); +} + +function fixCodeFormatting() { + + var $code = $(this); + $code.text($code.text().trim().replace(/;\n\s*/g, ';\n')); +} + + function onEnd() { var runner = this; var failed = runner.stats.failures > 0; - var stats = (runner.stats.duration / 1000.0).toFixed(2) + 's'; + var stats = (runner.stats.duration / 1000.0).toFixed(3) + '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 .stats').on('click', toggleFailureFilter); } $('#report').addClass(failed ? 'fail' : 'pass'); $('#report .progress').hide(); $('#report .stats').text(stats); - - $('#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 = $('' + passed + '' + failed + ''); - - 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')); - }); + $('#mocha-overlay .suite').each(addSuiteStats); + $('#mocha-overlay code').each(fixCodeFormatting); } function onTest() { var runner = this; - var complete = runner.stats.tests; - var total = runner.total; - var percent = 100.0 - 100.0 * complete / total; + var percent = 100.0 - 100.0 * runner.stats.tests / runner.total; if (runner.stats.failures) { $('#report').addClass('fail');