summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorezubarev <zubarev.eugene@gmail.com>2016-05-06 13:20:40 +0600
committerezubarev <zubarev.eugene@gmail.com>2016-05-06 13:20:40 +0600
commitd474084c90a60648fea6900ea5376d76c74bc222 (patch)
tree9766372d4ebadf8b53fb61dd07493f6b8d8322fd
parent764600eef0801abd7afbd9cd2a0878c17c3a101e (diff)
downloadasync-d474084c90a60648fea6900ea5376d76c74bc222.tar.gz
Convert sortBy/whilst/until tests to mocha
-rw-r--r--mocha_test/sortBy.js36
-rw-r--r--mocha_test/until.js93
-rw-r--r--mocha_test/whilst.js123
-rwxr-xr-xtest/test-async.js253
4 files changed, 252 insertions, 253 deletions
diff --git a/mocha_test/sortBy.js b/mocha_test/sortBy.js
new file mode 100644
index 0000000..1636276
--- /dev/null
+++ b/mocha_test/sortBy.js
@@ -0,0 +1,36 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var assert = require('assert');
+
+describe('sortBy', function(){
+ it('sortBy', function(done) {
+ async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
+ setTimeout(function(){callback(null, x.a);}, 0);
+ }, function(err, result){
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.eql([{a:1},{a:6},{a:15}]);
+ done();
+ });
+ });
+
+ it('sortBy inverted', function(done) {
+ async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
+ setTimeout(function(){callback(null, x.a*-1);}, 0);
+ }, function(err, result){
+ expect(result).to.eql([{a:15},{a:6},{a:1}]);
+ done();
+ });
+ });
+
+ it('sortBy error', function(done) {
+ var error = new Error('asdas');
+ async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
+ async.setImmediate(function(){
+ callback(error);
+ });
+ }, function(err){
+ expect(err).to.equal(error);
+ done();
+ });
+ });
+});
diff --git a/mocha_test/until.js b/mocha_test/until.js
new file mode 100644
index 0000000..a738218
--- /dev/null
+++ b/mocha_test/until.js
@@ -0,0 +1,93 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var assert = require('assert');
+
+describe('until', function(){
+ it('until', function(done) {
+ var call_order = [];
+ var count = 0;
+ async.until(
+ function () {
+ call_order.push(['test', count]);
+ return (count == 5);
+ },
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function (err, result) {
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['test', 0],
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5],
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+
+ it('doUntil', function(done) {
+ var call_order = [];
+ var count = 0;
+ async.doUntil(
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function () {
+ call_order.push(['test', count]);
+ return (count == 5);
+ },
+ function (err, result) {
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5]
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+
+ it('doUntil callback params', function(done) {
+ var call_order = [];
+ var count = 0;
+ async.doUntil(
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function (c) {
+ call_order.push(['test', c]);
+ return (c == 5);
+ },
+ function (err, result) {
+ if (err) throw err;
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5]
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+});
diff --git a/mocha_test/whilst.js b/mocha_test/whilst.js
new file mode 100644
index 0000000..a384916
--- /dev/null
+++ b/mocha_test/whilst.js
@@ -0,0 +1,123 @@
+var async = require('../lib');
+var expect = require('chai').expect;
+var assert = require('assert');
+
+describe('whilst', function(){
+ it('whilst', function(done) {
+ var call_order = [];
+
+ var count = 0;
+ async.whilst(
+ function () {
+ call_order.push(['test', count]);
+ return (count < 5);
+ },
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function (err, result) {
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['test', 0],
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5],
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+
+ it('whilst optional callback', function(done) {
+ var counter = 0;
+ async.whilst(
+ function () { return counter < 2; },
+ function (cb) {
+ counter++;
+ cb();
+ }
+ );
+ expect(counter).to.equal(2);
+ done();
+ });
+
+ it('doWhilst', function(done) {
+ var call_order = [];
+
+ var count = 0;
+ async.doWhilst(
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function () {
+ call_order.push(['test', count]);
+ return (count < 5);
+ },
+ function (err, result) {
+ assert(err === null, err + " passed instead of 'null'");
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5]
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+
+ it('doWhilst callback params', function(done) {
+ var call_order = [];
+ var count = 0;
+ async.doWhilst(
+ function (cb) {
+ call_order.push(['iteratee', count]);
+ count++;
+ cb(null, count);
+ },
+ function (c) {
+ call_order.push(['test', c]);
+ return (c < 5);
+ },
+ function (err, result) {
+ if (err) throw err;
+ expect(result).to.equal(5, 'last result passed through');
+ expect(call_order).to.eql([
+ ['iteratee', 0], ['test', 1],
+ ['iteratee', 1], ['test', 2],
+ ['iteratee', 2], ['test', 3],
+ ['iteratee', 3], ['test', 4],
+ ['iteratee', 4], ['test', 5]
+ ]);
+ expect(count).to.equal(5);
+ done();
+ }
+ );
+ });
+
+ it('doWhilst - error', function(done) {
+ var error = new Error('asdas');
+
+ async.doWhilst(
+ function (cb) {
+ cb(error);
+ },
+ function () {},
+ function (err) {
+ expect(err).to.equal(error);
+ done();
+ }
+ );
+ });
+});
diff --git a/test/test-async.js b/test/test-async.js
index 5530d72..45d916a 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -16,42 +16,6 @@ if (!Function.prototype.bind) {
};
}
-exports['sortBy'] = function(test){
- test.expect(2);
-
- async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
- setTimeout(function(){callback(null, x.a);}, 0);
- }, function(err, result){
- test.ok(err === null, err + " passed instead of 'null'");
- test.same(result, [{a:1},{a:6},{a:15}]);
- test.done();
- });
-};
-
-exports['sortBy inverted'] = function(test){
- test.expect(1);
-
- async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
- setTimeout(function(){callback(null, x.a*-1);}, 0);
- }, function(err, result){
- test.same(result, [{a:15},{a:6},{a:1}]);
- test.done();
- });
-};
-
-exports['sortBy error'] = function(test){
- test.expect(1);
- var error = new Error('asdas');
- async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){
- async.setImmediate(function(){
- callback(error);
- });
- }, function(err){
- test.equal(err, error);
- test.done();
- });
-};
-
exports['apply'] = function(test){
test.expect(6);
var fn = function(){
@@ -193,210 +157,6 @@ exports['concatSeries'] = function(test){
});
};
-exports['until'] = function (test) {
- test.expect(4);
-
- var call_order = [];
- var count = 0;
- async.until(
- function () {
- call_order.push(['test', count]);
- return (count == 5);
- },
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function (err, result) {
- test.ok(err === null, err + " passed instead of 'null'");
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['test', 0],
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5],
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['doUntil'] = function (test) {
- test.expect(4);
-
- var call_order = [];
- var count = 0;
- async.doUntil(
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function () {
- call_order.push(['test', count]);
- return (count == 5);
- },
- function (err, result) {
- test.ok(err === null, err + " passed instead of 'null'");
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5]
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['doUntil callback params'] = function (test) {
- test.expect(3);
-
- var call_order = [];
- var count = 0;
- async.doUntil(
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function (c) {
- call_order.push(['test', c]);
- return (c == 5);
- },
- function (err, result) {
- if (err) throw err;
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5]
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['whilst'] = function (test) {
- test.expect(4);
-
- var call_order = [];
-
- var count = 0;
- async.whilst(
- function () {
- call_order.push(['test', count]);
- return (count < 5);
- },
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function (err, result) {
- test.ok(err === null, err + " passed instead of 'null'");
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['test', 0],
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5],
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['doWhilst'] = function (test) {
- test.expect(4);
- var call_order = [];
-
- var count = 0;
- async.doWhilst(
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function () {
- call_order.push(['test', count]);
- return (count < 5);
- },
- function (err, result) {
- test.ok(err === null, err + " passed instead of 'null'");
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5]
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['doWhilst callback params'] = function (test) {
- test.expect(3);
- var call_order = [];
- var count = 0;
- async.doWhilst(
- function (cb) {
- call_order.push(['iteratee', count]);
- count++;
- cb(null, count);
- },
- function (c) {
- call_order.push(['test', c]);
- return (c < 5);
- },
- function (err, result) {
- if (err) throw err;
- test.equals(result, 5, 'last result passed through');
- test.same(call_order, [
- ['iteratee', 0], ['test', 1],
- ['iteratee', 1], ['test', 2],
- ['iteratee', 2], ['test', 3],
- ['iteratee', 3], ['test', 4],
- ['iteratee', 4], ['test', 5]
- ]);
- test.equals(count, 5);
- test.done();
- }
- );
-};
-
-exports['doWhilst - error'] = function (test) {
- test.expect(1);
- var error = new Error('asdas');
-
- async.doWhilst(
- function (cb) {
- cb(error);
- },
- function () {},
- function (err) {
- test.equal(err, error);
- test.done();
- }
- );
-};
-
exports['during'] = function (test) {
var call_order = [];
@@ -490,19 +250,6 @@ exports['doDuring - error iteratee'] = function (test) {
);
};
-exports['whilst optional callback'] = function (test) {
- var counter = 0;
- async.whilst(
- function () { return counter < 2; },
- function (cb) {
- counter++;
- cb();
- }
- );
- test.equal(counter, 2);
- test.done();
-};
-
exports['ensureAsync'] = {
'defer sync functions': function (test) {
test.expect(6);