diff options
| author | Caolan McMahon <caolan@caolanmcmahon.com> | 2011-01-18 09:56:09 +0000 |
|---|---|---|
| committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2011-01-18 09:56:09 +0000 |
| commit | 4e090dbcd4fd03292cdb3fa4acd4ce1378d12f3e (patch) | |
| tree | 465f4c0c07d1a71c076894a46551005ec3323bb7 | |
| parent | 74b9dc2a6c149daa6ca09f63e327f2da8eafd329 (diff) | |
| parent | a10cdaec3e43f852505ce5ba1b7ba5612084e17a (diff) | |
| download | async-4e090dbcd4fd03292cdb3fa4acd4ce1378d12f3e.tar.gz | |
Merge branch 'master' of git@github.com:caolan/async
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | deps/nodeunit.css | 70 | ||||
| -rw-r--r-- | deps/nodeunit.js | 158 | ||||
| -rw-r--r-- | dist/async.min.js | 2 | ||||
| -rw-r--r-- | lib/async.js | 14 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | test/test-async.js | 28 | ||||
| -rw-r--r-- | test/test.html | 4 |
8 files changed, 171 insertions, 111 deletions
@@ -635,10 +635,10 @@ __Example__ async.waterfall([ function(callback){ callback(null, 'one', 'two'); - } + }, function(arg1, arg2, callback){ callback(null, 'three'); - } + }, function(arg1, callback){ // arg1 now equals 'three' callback(null, 'done'); diff --git a/deps/nodeunit.css b/deps/nodeunit.css new file mode 100644 index 0000000..274434a --- /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 a4ae88c..5957184 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 += '<style type="text/css">' + - 'body { font: 12px Helvetica Neue }' + - 'h2 { margin:0 ; padding:0 }' + - 'pre {' + - 'font: 11px Andale Mono;' + - 'margin-left: 1em;' + - 'padding-left: 1em;' + - 'margin-top: 0;' + - 'font-size:smaller;' + - '}' + - '.assertion_message { margin-left: 1em; }' + - ' ol {' + - 'list-style: none;' + - 'margin-left: 1em;' + - 'padding-left: 1em;' + - 'text-indent: -1em;' + - '}' + - ' ol li.pass:before { content: "\\2714 \\0020"; }' + - ' ol li.fail:before { content: "\\2716 \\0020"; }' + - '</style>'; -}; - - /** * 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<assertions.length; i++) { - var a = assertions[i]; - if (a.failed()) { - if (a.error instanceof assert.AssertionError && a.message) { - html += '<div class="assertion_message">' + - 'Assertion Message: ' + a.message + - '</div>'; - } - html += '<pre>'; - html += a.error.stack || a.error; - html += '</pre>'; - } - }; - test.innerHTML = html; + var strong = document.createElement('strong'); + strong.innerHTML = name + ' <b style="color: black;">(' + + '<b class="fail">' + assertions.failures() + '</b>, ' + + '<b class="pass">' + assertions.passes() + '</b>, ' + + assertions.length + + ')</b>'; + 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<assertions.length; i++) { + var li = document.createElement('li'); + var a = assertions[i]; + if (a.failed()) { + li.innerHTML = (a.message || a.method || 'no message') + + '<pre>' + (a.error.stack || a.error) + '</pre>'; + 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.<br/><span class="passed">' + + assertions.passes() + '</span> assertions of ' + + '<span class="all">' + assertions.length + '<span> passed, ' + + assertions.failures() + ' failed.'; } }); }; diff --git a/dist/async.min.js b/dist/async.min.js index b8d1fe7..c25ae30 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;c<a.length;c+=1)b(a[c],c,a)};var e=function(a,b){if(a.map)return a.map(b);var c=[];d(a,function(a,d,e){c.push(b(a,d,e))});return c};var f=function(a,b,c){if(a.reduce)return a.reduce(b,c);d(a,function(a,d,e){c=b(c,a,d,e)});return c};var g=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};var h=function(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;c<a.length;c+=1)if(a[c]===b)return c;return-1};a.nextTick=function(a){typeof process==="undefined"||!process.nextTick?setTimeout(a,0):process.nextTick(a)},a.forEach=function(a,b,c){if(!a.length)return c();var e=0;d(a,function(d){b(d,function(b){b?(c(b),c=function(){}):(e+=1,e===a.length&&c())})})},a.forEachSeries=function(a,b,c){if(!a.length)return c();var d=0;var e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d===a.length?c():e())})};e()};var i=function(b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[a.forEach].concat(c))}};var j=function(b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[a.forEachSeries].concat(c))}};var k=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c,d){f[a.index]=d,b(c)})},function(a){d(a,f)})};a.map=i(k),a.mapSeries=j(k),a.reduce=function(b,c,d,e){a.forEachSeries(b,function(a,b){d(c,a,function(a,d){c=d,b(a)})},function(a){e(a,c)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(b,c,d,f){var g=e(b,function(a){return a}).reverse();a.reduce(g,c,d,f)},a.foldr=a.reduceRight;var l=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&f.push(a),b()})},function(a){d(e(f.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};a.filter=i(l),a.filterSeries=j(l),a.select=a.filter,a.selectSeries=a.filterSeries;var m=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||f.push(a),b()})},function(a){d(e(f.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};a.reject=i(m),a.rejectSeries=j(m);var n=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?d(a):b()})},function(a){d()})};a.detect=i(n),a.detectSeries=j(n),a.some=function(b,c,d){a.forEach(b,function(a,b){c(a,function(a){a&&(d(true),d=function(){}),b()})},function(a){d(false)})},a.any=a.some,a.every=function(b,c,d){a.forEach(b,function(a,b){c(a,function(a){a||(d(false),d=function(){}),b()})},function(a){d(true)})},a.all=a.every,a.sortBy=function(b,c,d){a.map(b,function(a,b){c(a,function(c,d){c?b(c):b(null,{value:a,criteria:d})})},function(a,b){if(a)return d(a);var c=function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?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<i.length;b+=1)if(i[b]===a){i.splice(b,1);return}};var l=function(){d(i,function(a){a()})};j(function(){e.length===c.length&&b(null)}),d(c,function(c){var d=a[c]instanceof Function?[a[c]]:a[c];var g=function(a){a?(b(a),b=function(){}):(e.push(c),l())};var i=d.slice(0,Math.abs(d.length-1))||[];var m=function(){return f(i,function(a,b){return a&&h(e,b)!==-1},true)};if(m())d[d.length-1](g);else{var n=function(){m()&&(k(n),d[d.length-1](g))};j(n)}})},a.waterfall=function(b,c){if(!b.length)return c();c=c||function(){};var d=function(b){return function(e){if(e)c(e),c=function(){};else{var f=Array.prototype.slice.call(arguments,1);var g=b.next();g?f.push(d(g)):f.push(c),a.nextTick(function(){b.apply(null,f)})}}};d(a.iterator(b))()},a.parallel=function(b,c){c=c||function(){};if(b.constructor===Array)a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c||null)})},c);else{var d={};a.forEach(g(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}},a.series=function(b,c){c=c||function(){};if(b.constructor===Array)a.mapSeries(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c||null)})},c);else{var d={};a.forEachSeries(g(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}},a.iterator=function(a){var b=function(c){var d=function(){a.length&&a[c].apply(null,arguments);return d.next()};d.next=function(){return c<a.length-1?b(c+1):null};return d};return b(0)},a.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var o=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};a.concat=i(o),a.concatSeries=j(o),a.whilst=function(b,c,d){b()?c(function(e){if(e)return d(e);a.whilst(b,c,d)}):d()},a.until=function(b,c,d){b()?d():c(function(e){if(e)return d(e);a.until(b,c,d)})},a.queue=function(b,c){var d=0;var e=[];var f={concurrency:c,push:function(b,c){e.push({data:b,callback:c}),a.nextTick(f.process)},process:function(){if(d<f.concurrency&&e.length){var a=e.splice(0,1)[0];d+=1,b(a.data,function(){d-=1,a.callback&&a.callback.apply(a,arguments),f.process()})}},length:function(){return e.length}};return f};var p=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);typeof console!=="undefined"&&(b?console.error&&console.error(b):console[a]&&d(c,function(b){console[a](b)}))}]))}};a.log=p("log"),a.dir=p("dir"),a.memoize=function(a,b){var c={};b=b||function(a){return a};return function(){var d=Array.prototype.slice.call(arguments);var e=d.pop();var f=b.apply(null,d);f in c?e.apply(null,c[f]):a.apply(null,d.concat([function(){c[f]=arguments,e.apply(null,arguments)}]))}}})()
\ No newline at end of file +/*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;c<a.length;c+=1)b(a[c],c,a)};var e=function(a,b){if(a.map)return a.map(b);var c=[];d(a,function(a,d,e){c.push(b(a,d,e))});return c};var f=function(a,b,c){if(a.reduce)return a.reduce(b,c);d(a,function(a,d,e){c=b(c,a,d,e)});return c};var g=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b};var h=function(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;c<a.length;c+=1)if(a[c]===b)return c;return-1};typeof process==="undefined"||!process.nextTick?a.nextTick=function(a){setTimeout(a,0)}:a.nextTick=process.nextTick,a.forEach=function(a,b,c){if(!a.length)return c();var e=0;d(a,function(d){b(d,function(b){b?(c(b),c=function(){}):(e+=1,e===a.length&&c())})})},a.forEachSeries=function(a,b,c){if(!a.length)return c();var d=0;var e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d===a.length?c():e())})};e()};var i=function(b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[a.forEach].concat(c))}};var j=function(b){return function(){var c=Array.prototype.slice.call(arguments);return b.apply(null,[a.forEachSeries].concat(c))}};var k=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c,d){f[a.index]=d,b(c)})},function(a){d(a,f)})};a.map=i(k),a.mapSeries=j(k),a.reduce=function(b,c,d,e){a.forEachSeries(b,function(a,b){d(c,a,function(a,d){c=d,b(a)})},function(a){e(a,c)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(b,c,d,f){var g=e(b,function(a){return a}).reverse();a.reduce(g,c,d,f)},a.foldr=a.reduceRight;var l=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c&&f.push(a),b()})},function(a){d(e(f.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};a.filter=i(l),a.filterSeries=j(l),a.select=a.filter,a.selectSeries=a.filterSeries;var m=function(a,b,c,d){var f=[];b=e(b,function(a,b){return{index:b,value:a}}),a(b,function(a,b){c(a.value,function(c){c||f.push(a),b()})},function(a){d(e(f.sort(function(a,b){return a.index-b.index}),function(a){return a.value}))})};a.reject=i(m),a.rejectSeries=j(m);var n=function(a,b,c,d){a(b,function(a,b){c(a,function(c){c?d(a):b()})},function(a){d()})};a.detect=i(n),a.detectSeries=j(n),a.some=function(b,c,d){a.forEach(b,function(a,b){c(a,function(a){a&&(d(true),d=function(){}),b()})},function(a){d(false)})},a.any=a.some,a.every=function(b,c,d){a.forEach(b,function(a,b){c(a,function(a){a||(d(false),d=function(){}),b()})},function(a){d(true)})},a.all=a.every,a.sortBy=function(b,c,d){a.map(b,function(a,b){c(a,function(c,d){c?b(c):b(null,{value:a,criteria:d})})},function(a,b){if(a)return d(a);var c=function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?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<i.length;b+=1)if(i[b]===a){i.splice(b,1);return}};var l=function(){d(i,function(a){a()})};j(function(){e.length===c.length&&b(null)}),d(c,function(c){var d=a[c]instanceof Function?[a[c]]:a[c];var g=function(a){a?(b(a),b=function(){}):(e.push(c),l())};var i=d.slice(0,Math.abs(d.length-1))||[];var m=function(){return f(i,function(a,b){return a&&h(e,b)!==-1},true)};if(m())d[d.length-1](g);else{var n=function(){m()&&(k(n),d[d.length-1](g))};j(n)}})},a.waterfall=function(b,c){if(!b.length)return c();c=c||function(){};var d=function(b){return function(e){if(e)c(e),c=function(){};else{var f=Array.prototype.slice.call(arguments,1);var g=b.next();g?f.push(d(g)):f.push(c),a.nextTick(function(){b.apply(null,f)})}}};d(a.iterator(b))()},a.parallel=function(b,c){c=c||function(){};if(b.constructor===Array)a.map(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c||null)})},c);else{var d={};a.forEach(g(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}},a.series=function(b,c){c=c||function(){};if(b.constructor===Array)a.mapSeries(b,function(a,b){a&&a(function(a){var c=Array.prototype.slice.call(arguments,1);c.length<=1&&(c=c[0]),b.call(null,a,c||null)})},c);else{var d={};a.forEachSeries(g(b),function(a,c){b[a](function(b){var e=Array.prototype.slice.call(arguments,1);e.length<=1&&(e=e[0]),d[a]=e,c(b)})},function(a){c(a,d)})}},a.iterator=function(a){var b=function(c){var d=function(){a.length&&a[c].apply(null,arguments);return d.next()};d.next=function(){return c<a.length-1?b(c+1):null};return d};return b(0)},a.apply=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b.concat(Array.prototype.slice.call(arguments)))}};var o=function(a,b,c,d){var e=[];a(b,function(a,b){c(a,function(a,c){e=e.concat(c||[]),b(a)})},function(a){d(a,e)})};a.concat=i(o),a.concatSeries=j(o),a.whilst=function(b,c,d){b()?c(function(e){if(e)return d(e);a.whilst(b,c,d)}):d()},a.until=function(b,c,d){b()?d():c(function(e){if(e)return d(e);a.until(b,c,d)})},a.queue=function(b,c){var d=0;var e=[];var f={concurrency:c,push:function(b,c){e.push({data:b,callback:c}),a.nextTick(f.process)},process:function(){if(d<f.concurrency&&e.length){var a=e.splice(0,1)[0];d+=1,b(a.data,function(){d-=1,a.callback&&a.callback.apply(a,arguments),f.process()})}},length:function(){return e.length}};return f};var p=function(a){return function(b){var c=Array.prototype.slice.call(arguments,1);b.apply(null,c.concat([function(b){var c=Array.prototype.slice.call(arguments,1);typeof console!=="undefined"&&(b?console.error&&console.error(b):console[a]&&d(c,function(b){console[a](b)}))}]))}};a.log=p("log"),a.dir=p("dir"),a.memoize=function(a,b){var c={};b=b||function(a){return a};return function(){var d=Array.prototype.slice.call(arguments);var e=d.pop();var f=b.apply(null,d);f in c?e.apply(null,c[f]):a.apply(null,d.concat([function(){c[f]=arguments,e.apply(null,arguments)}]))}}})()
\ No newline at end of file diff --git a/lib/async.js b/lib/async.js index 4fc4de6..250d8e9 100644 --- a/lib/async.js +++ b/lib/async.js @@ -79,14 +79,14 @@ //// exported async module functions //// //// nextTick implementation with browser-compatible fallback //// - async.nextTick = function (fn) { - if (typeof process === 'undefined' || !(process.nextTick)) { + if (typeof process === 'undefined' || !(process.nextTick)) { + async.nextTick = function (fn) { setTimeout(fn, 0); - } - else { - process.nextTick(fn); - } - }; + }; + } + else { + async.nextTick = process.nextTick; + } async.forEach = function (arr, iterator, callback) { if (!arr.length) { diff --git a/package.json b/package.json index 8324a18..95282e2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ , "description": "Higher-order functions and common patterns for asynchronous code" , "main": "./index" , "author": "Caolan McMahon" -, "version": "0.1.6" +, "version": "0.1.7" , "repository" : { "type" : "git" , "url" : "http://github.com/caolan/async.git" diff --git a/test/test-async.js b/test/test-async.js index 4dc57f9..38edb72 100644 --- a/test/test-async.js +++ b/test/test-async.js @@ -893,34 +893,12 @@ exports['nextTick'] = function(test){ }, 50); }; -exports['nextTick in node'] = function(test){ - test.expect(1); - var browser = false; - if (typeof process === 'undefined') { - browser = true; - window.process = {}; - } - var _nextTick = process.nextTick; - process.nextTick = function(){ - if (browser) { - window.process = undefined; - } - else { - process.nextTick = _nextTick; - } - test.ok(true, 'process.nextTick called'); - test.done(); - }; - async.nextTick(function(){}); -}; - exports['nextTick in the browser'] = function(test){ - test.expect(1); - if (typeof process !== 'undefined') { - var _nextTick = process.nextTick; - process.nextTick = undefined; + // skip this test in node + return test.done(); } + test.expect(1); var call_order = []; async.nextTick(function(){call_order.push('two');}); diff --git a/test/test.html b/test/test.html index fb5399c..2450e2d 100644 --- a/test/test.html +++ b/test/test.html @@ -1,12 +1,13 @@ <html> <head> - <title>Async.js tests</title> + <title>Async.js Test Suite</title> <!-- async must be included after nodeunit because nodeunit already uses the async lib internally and will overwrite the version we want to test --> <script src="../deps/nodeunit.js"></script> <script src="../lib/async.js"></script> + <link rel="stylesheet" href="../deps/nodeunit.css" type="text/css" media="screen" /> <script> var _async = this.async; this.require = function () { return _async; }; @@ -15,6 +16,7 @@ <script src="test-async.js"></script> </head> <body> + <h1 id="nodeunit-header">Async.js Test Suite</h1> <script> nodeunit.run({'test-async': exports}); </script> |
