From 21c976bb3db5048cec61fb23fdaf9c5090c5ea4f Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 26 Apr 2015 20:02:23 +0200 Subject: [PATCH] Update test runner. --- test/index.html.jade | 2 ++ test/styles.less | 78 +++++++++++++++++++++++++------------------- test/util/mocha.js | 46 +++++++++++++++++--------- 3 files changed, 77 insertions(+), 49 deletions(-) diff --git a/test/index.html.jade b/test/index.html.jade index 14b528e4..a90425ed 100644 --- a/test/index.html.jade +++ b/test/index.html.jade @@ -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 diff --git a/test/styles.less b/test/styles.less index 6ac00f44..5f7d11d7 100644 --- a/test/styles.less +++ b/test/styles.less @@ -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; + // } } diff --git a/test/util/mocha.js b/test/util/mocha.js index 906f3a19..47a75643 100644 --- a/test/util/mocha.js +++ b/test/util/mocha.js @@ -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('passes:'); - $('#mocha-stats .failures a').replaceWith('failures:'); +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 || {};