diff options
author | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 12:00:28 +0600 |
---|---|---|
committer | ezubarev <zubarev.eugene@gmail.com> | 2016-05-06 12:00:28 +0600 |
commit | 4abd0d1c8e57796d648576e2976c2aabba58317c (patch) | |
tree | fe4c53ed14d6342f7b1b26b4cd2375aa8eed3157 | |
parent | f71051575026ba91cf595594dd9b245d5c448852 (diff) | |
download | async-4abd0d1c8e57796d648576e2976c2aabba58317c.tar.gz |
Convert times tests to mocha
-rw-r--r-- | mocha_test/times.js | 90 | ||||
-rwxr-xr-x | test/test-async.js | 97 |
2 files changed, 90 insertions, 97 deletions
diff --git a/mocha_test/times.js b/mocha_test/times.js new file mode 100644 index 0000000..ad1dfcd --- /dev/null +++ b/mocha_test/times.js @@ -0,0 +1,90 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('times', function() { + + it('times', function(done) { + async.times(5, function(n, next) { + next(null, n); + }, function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([0,1,2,3,4]); + done(); + }); + }); + + it('times 3', function(done) { + var args = []; + async.times(3, function(n, callback){ + setTimeout(function(){ + args.push(n); + callback(); + }, n * 25); + }, function(err){ + if (err) throw err; + expect(args).to.eql([0,1,2]); + done(); + }); + }); + + it('times 0', function(done) { + async.times(0, function(n, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('times error', function(done) { + async.times(3, function(n, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('timesSeries', function(done) { + var call_order = []; + async.timesSeries(5, function(n, callback){ + setTimeout(function(){ + call_order.push(n); + callback(null, n); + }, 100 - n * 10); + }, function(err, results){ + expect(call_order).to.eql([0,1,2,3,4]); + expect(results).to.eql([0,1,2,3,4]); + done(); + }); + }); + + it('timesSeries error', function(done) { + async.timesSeries(5, function(n, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('timesLimit', function(done) { + var limit = 2; + var running = 0; + async.timesLimit(5, limit, function (i, next) { + running++; + assert(running <= limit && running > 0, running); + setTimeout(function () { + running--; + next(null, i * 2); + }, (3 - i) * 10); + }, function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([0, 2, 4, 6, 8]); + done(); + }); + }); +}); diff --git a/test/test-async.js b/test/test-async.js index 763fb31..d5cb5e9 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -413,103 +413,6 @@ var console_fn_tests = function(name){ }; - -exports['times'] = { - - 'times': function(test) { - test.expect(2); - async.times(5, function(n, next) { - next(null, n); - }, function(err, results) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [0,1,2,3,4]); - test.done(); - }); -}, - - 'times 3': function(test){ - test.expect(1); - var args = []; - async.times(3, function(n, callback){ - setTimeout(function(){ - args.push(n); - callback(); - }, n * 25); - }, function(err){ - if (err) throw err; - test.same(args, [0,1,2]); - test.done(); - }); -}, - - 'times 0': function(test){ - test.expect(1); - async.times(0, function(n, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}, - - 'times error': function(test){ - test.expect(1); - async.times(3, function(n, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'timesSeries': function(test){ - test.expect(2); - var call_order = []; - async.timesSeries(5, function(n, callback){ - setTimeout(function(){ - call_order.push(n); - callback(null, n); - }, 100 - n * 10); - }, function(err, results){ - test.same(call_order, [0,1,2,3,4]); - test.same(results, [0,1,2,3,4]); - test.done(); - }); -}, - - 'timesSeries error': function(test){ - test.expect(1); - async.timesSeries(5, function(n, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'timesLimit': function(test){ - test.expect(7); - - var limit = 2; - var running = 0; - async.timesLimit(5, limit, function (i, next) { - running++; - test.ok(running <= limit && running > 0, running); - setTimeout(function () { - running--; - next(null, i * 2); - }, (3 - i) * 10); - }, function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [0, 2, 4, 6, 8]); - test.done(); - }); -} - -}; - console_fn_tests('log'); console_fn_tests('dir'); /*console_fn_tests('info'); |