From cb1825c7e64eb83011fced190386f4bc660570d7 Mon Sep 17 00:00:00 2001 From: Caolan McMahon Date: Sun, 19 Dec 2010 16:34:57 +0000 Subject: [PATCH] updated nodeunit deps --- deps/nodeunit.css | 70 ++++++++++++++++++++ deps/nodeunit.js | 158 ++++++++++++++++++++++++--------------------- dist/async.min.js | 2 +- test/test-async.js | 14 ++-- test/test.html | 4 +- 5 files changed, 162 insertions(+), 86 deletions(-) create mode 100644 deps/nodeunit.css diff --git a/deps/nodeunit.css b/deps/nodeunit.css new file mode 100644 index 000000000..274434a4a --- /dev/null +++ b/deps/nodeunit.css @@ -0,0 +1,70 @@ +/*! + * Styles taken from qunit.css + */ + +h1#nodeunit-header, h1.nodeunit-header { + padding: 15px; + font-size: large; + background-color: #06b; + color: white; + font-family: 'trebuchet ms', verdana, arial; + margin: 0; +} + +h1#nodeunit-header a { + color: white; +} + +h2#nodeunit-banner { + height: 2em; + border-bottom: 1px solid white; + background-color: #eee; + margin: 0; + font-family: 'trebuchet ms', verdana, arial; +} +h2#nodeunit-banner.pass { + background-color: green; +} +h2#nodeunit-banner.fail { + background-color: red; +} + +h2#nodeunit-userAgent, h2.nodeunit-userAgent { + padding: 10px; + background-color: #eee; + color: black; + margin: 0; + font-size: small; + font-weight: normal; + font-family: 'trebuchet ms', verdana, arial; + font-size: 10pt; +} + +div#nodeunit-testrunner-toolbar { + background: #eee; + border-top: 1px solid black; + padding: 10px; + font-family: 'trebuchet ms', verdana, arial; + margin: 0; + font-size: 10pt; +} + +ol#nodeunit-tests { + font-family: 'trebuchet ms', verdana, arial; + font-size: 10pt; +} +ol#nodeunit-tests li strong { + cursor:pointer; +} +ol#nodeunit-tests .pass { + color: green; +} +ol#nodeunit-tests .fail { + color: red; +} + +p#nodeunit-testresult { + margin-left: 1em; + font-size: 10pt; + font-family: 'trebuchet ms', verdana, arial; +} diff --git a/deps/nodeunit.js b/deps/nodeunit.js index a4ae88c93..59571840c 100644 --- a/deps/nodeunit.js +++ b/deps/nodeunit.js @@ -1475,6 +1475,9 @@ exports.assertionList = function (arr, duration) { } return failures; }; + that.passes = function () { + return that.length - that.failures(); + }; that.duration = duration || 0; return that; }; @@ -1521,9 +1524,11 @@ exports.test = function (name, start, options, callback) { var wrapAssert = assertWrapper(function (a) { a_list.push(a); - async.nextTick(function () { - options.log(a); - }); + if (options.log) { + async.nextTick(function () { + options.log(a); + }); + } }); var test = { @@ -1535,16 +1540,20 @@ exports.test = function (name, start, options, callback) { ); var a1 = exports.assertion({method: 'expect', error: e}); a_list.push(a1); - async.nextTick(function () { - options.log(a1); - }); + if (options.log) { + async.nextTick(function () { + options.log(a1); + }); + } } if (err) { var a2 = exports.assertion({error: err}); a_list.push(a2); - async.nextTick(function () { - options.log(a2); - }); + if (options.log) { + async.nextTick(function () { + options.log(a2); + }); + } } var end = new Date().getTime(); async.nextTick(function () { @@ -1588,7 +1597,7 @@ exports.options = function (opt) { optionalCallback('moduleDone'); optionalCallback('testStart'); optionalCallback('testDone'); - optionalCallback('log'); + //optionalCallback('log'); // 'done' callback is not optional. @@ -1855,30 +1864,6 @@ exports.testCase = function (suite) { exports.info = "Browser-based test reporter"; -exports.addStyles = function () { - document.body.innerHTML += ''; -}; - - /** * Run all tests within each module, reporting the results * @@ -1888,63 +1873,88 @@ exports.addStyles = function () { exports.run = function (modules, options) { var start = new Date().getTime(); - exports.addStyles(); - var results, module; + function setText(el, txt) { + if ('innerText' in el) { + el.innerText = txt; + } + else if ('textContent' in el){ + el.textContent = txt; + } + } + + function getOrCreate(tag, id) { + var el = document.getElementById(id); + if (!el) { + el = document.createElement(tag); + el.id = id; + document.body.appendChild(el); + } + return el; + }; + + var header = getOrCreate('h1', 'nodeunit-header'); + var banner = getOrCreate('h2', 'nodeunit-banner'); + var userAgent = getOrCreate('h2', 'nodeunit-userAgent'); + var tests = getOrCreate('ol', 'nodeunit-tests'); + var result = getOrCreate('p', 'nodeunit-testresult'); - results = document.createElement('div'); - results.id = 'results'; - document.body.appendChild(results); + setText(userAgent, navigator.userAgent); nodeunit.runModules(modules, { moduleStart: function (name) { - var mheading = document.createElement('h2'); + /*var mheading = document.createElement('h2'); mheading.innerText = name; results.appendChild(mheading); module = document.createElement('ol'); - results.appendChild(module); + results.appendChild(module);*/ }, testDone: function (name, assertions) { var test = document.createElement('li'); - if (!assertions.failures()) { - test.className = 'pass'; - test.innerText = name; - } - else { - test.className = 'fail'; - var html = name; - for (var i=0; i'; - } - html += '
';
-                        html += a.error.stack || a.error;
-                        html += '
'; - } - }; - test.innerHTML = html; + var strong = document.createElement('strong'); + strong.innerHTML = name + ' (' + + '' + assertions.failures() + ', ' + + '' + assertions.passes() + ', ' + + assertions.length + + ')'; + test.className = assertions.failures() ? 'fail': 'pass'; + test.appendChild(strong); + + var aList = document.createElement('ol'); + aList.style.display = 'none'; + test.onclick = function () { + var d = aList.style.display; + aList.style.display = (d == 'none') ? 'block': 'none'; + }; + for (var i=0; i' + (a.error.stack || a.error) + ''; + li.className = 'fail'; + } + else { + li.innerHTML = a.message || a.method || 'no message'; + li.className = 'pass'; + } + aList.appendChild(li); } - module.appendChild(test); + test.appendChild(aList); + tests.appendChild(test); }, done: function (assertions) { var end = new Date().getTime(); var duration = end - start; - var summary = document.createElement('h3'); - if (assertions.failures()) { - summary.innerText = 'FAILURES: ' + assertions.failures() + - '/' + assertions.length + ' assertions failed (' + - assertions.duration + 'ms)'; - } - else { - summary.innerText = 'OK: ' + assertions.length + - ' assertions (' + assertions.duration + 'ms)'; - } - document.body.appendChild(summary); + var failures = assertions.failures(); + banner.className = failures ? 'fail': 'pass'; + + result.innerHTML = 'Tests completed in ' + duration + + ' milliseconds.
' + + assertions.passes() + ' assertions of ' + + '' + assertions.length + ' passed, ' + + assertions.failures() + ' failed.'; } }); }; diff --git a/dist/async.min.js b/dist/async.min.js index b8d1fe70e..a2547ffbe 100644 --- a/dist/async.min.js +++ b/dist/async.min.js @@ -1 +1 @@ -/*global setTimeout: false, console: false */(function(){var a={};var b=this,c=b.async;typeof module!=="undefined"&&module.exports?module.exports=a:b.async=a,a.noConflict=function(){b.async=c;return a};var d=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;cd?1:0};d(null,e(b.sort(c),function(a){return a.value}))})},a.auto=function(a,b){b=b||function(){};var c=g(a);if(!c.length)return b(null);var e=[];var i=[];var j=function(a){i.unshift(a)};var k=function(a){for(var b=0;bd?1:0};d(null,e(b.sort(c),function(a){return a.value}))})},a.auto=function(a,b){b=b||function(){};var c=g(a);if(!c.length)return b(null);var e=[];var i=[];var j=function(a){i.unshift(a)};var k=function(a){for(var b=0;b - Async.js tests + Async.js Test Suite + +

Async.js Test Suite