summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2015-06-24 15:05:40 -0700
committerAlexander Early <alexander.early@gmail.com>2015-06-24 15:05:40 -0700
commit6c3ca7ab22f477527d1f851311c1e8989e56e64f (patch)
tree20735af1679a315b971fa916f88b63074cce3f1d
parent4722bb5703d7c53ed802e6d21c951cee061e9181 (diff)
parent302713b06c2f2384b17fa5aec2866ccb0f4e610b (diff)
downloadasync-6c3ca7ab22f477527d1f851311c1e8989e56e64f.tar.gz
Merge pull request #802 from megawac/expect-test
Add expect statements to (many) tests
-rwxr-xr-xtest/test-async.js122
1 files changed, 94 insertions, 28 deletions
diff --git a/test/test-async.js b/test/test-async.js
index 8b2f87f..11685df 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -2172,6 +2172,7 @@ exports['selectSeries alias'] = function(test){
};
exports['reject'] = function(test){
+ test.expect(1);
async.reject([3,1,2], filterIterator, function(results){
test.same(results, [2]);
test.done();
@@ -2179,6 +2180,7 @@ exports['reject'] = function(test){
};
exports['reject original untouched'] = function(test){
+ test.expect(2);
var a = [3,1,2];
async.reject(a, function(x, callback){
callback(x % 2);
@@ -2190,6 +2192,7 @@ exports['reject original untouched'] = function(test){
};
exports['rejectSeries'] = function(test){
+ test.expect(1);
async.rejectSeries([3,1,2], filterIterator, function(results){
test.same(results, [2]);
test.done();
@@ -2197,6 +2200,7 @@ exports['rejectSeries'] = function(test){
};
exports['some true'] = function(test){
+ test.expect(1);
async.some([3,1,2], function(x, callback){
setTimeout(function(){callback(x === 1);}, 0);
}, function(result){
@@ -2206,6 +2210,7 @@ exports['some true'] = function(test){
};
exports['some false'] = function(test){
+ test.expect(1);
async.some([3,1,2], function(x, callback){
setTimeout(function(){callback(x === 10);}, 0);
}, function(result){
@@ -2215,6 +2220,7 @@ exports['some false'] = function(test){
};
exports['some early return'] = function(test){
+ test.expect(1);
var call_order = [];
async.some([1,2,3], function(x, callback){
setTimeout(function(){
@@ -2236,6 +2242,7 @@ exports['any alias'] = function(test){
};
exports['every true'] = function(test){
+ test.expect(1);
async.every([1,2,3], function(x, callback){
setTimeout(function(){callback(true);}, 0);
}, function(result){
@@ -2245,6 +2252,7 @@ exports['every true'] = function(test){
};
exports['every false'] = function(test){
+ test.expect(1);
async.every([1,2,3], function(x, callback){
setTimeout(function(){callback(x % 2);}, 0);
}, function(result){
@@ -2254,6 +2262,7 @@ exports['every false'] = function(test){
};
exports['every early return'] = function(test){
+ test.expect(1);
var call_order = [];
async.every([1,2,3], function(x, callback){
setTimeout(function(){
@@ -2275,6 +2284,7 @@ exports['all alias'] = function(test){
};
exports['detect'] = function(test){
+ test.expect(2);
var call_order = [];
async.detect([3,2,1], detectIterator.bind(this, call_order), function(result){
call_order.push('callback');
@@ -2287,6 +2297,7 @@ exports['detect'] = function(test){
};
exports['detect - mulitple matches'] = function(test){
+ test.expect(2);
var call_order = [];
async.detect([3,2,2,1,2], detectIterator.bind(this, call_order), function(result){
call_order.push('callback');
@@ -2299,6 +2310,7 @@ exports['detect - mulitple matches'] = function(test){
};
exports['detectSeries'] = function(test){
+ test.expect(2);
var call_order = [];
async.detectSeries([3,2,1], detectIterator.bind(this, call_order), function(result){
call_order.push('callback');
@@ -2311,6 +2323,7 @@ exports['detectSeries'] = function(test){
};
exports['detectSeries - multiple matches'] = function(test){
+ test.expect(2);
var call_order = [];
async.detectSeries([3,2,2,1,2], detectIterator.bind(this, call_order), function(result){
call_order.push('callback');
@@ -2323,6 +2336,7 @@ exports['detectSeries - multiple matches'] = function(test){
};
exports['detectSeries - ensure stop'] = function (test) {
+ test.expect(1);
async.detectSeries([1, 2, 3, 4, 5], function (num, cb) {
if (num > 3) throw new Error("detectSeries did not stop iterating");
cb(num === 3);
@@ -2333,6 +2347,8 @@ exports['detectSeries - ensure stop'] = function (test) {
};
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){
@@ -2343,6 +2359,8 @@ exports['sortBy'] = function(test){
};
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){
@@ -2400,6 +2418,7 @@ var console_fn_tests = function(name){
};
exports[name + ' with multiple result params'] = function(test){
+ test.expect(1);
var fn = function(callback){callback(null,'one','two','three');};
var _console_fn = console[name];
var called_with = [];
@@ -2433,16 +2452,18 @@ var console_fn_tests = function(name){
exports['times'] = {
'times': function(test) {
- 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();
- });
+ 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(){
@@ -2479,6 +2500,7 @@ exports['times'] = {
},
'timesSeries': function(test){
+ test.expect(2);
var call_order = [];
async.timesSeries(5, function(n, callback){
setTimeout(function(){
@@ -2503,6 +2525,8 @@ exports['times'] = {
},
'timesLimit': function(test){
+ test.expect(7);
+
var limit = 2;
var running = 0;
async.timesLimit(5, limit, function (i, next) {
@@ -2528,6 +2552,7 @@ console_fn_tests('warn');
console_fn_tests('error');*/
exports['nextTick'] = function(test){
+ test.expect(1);
var call_order = [];
async.nextTick(function(){call_order.push('two');});
call_order.push('one');
@@ -2586,6 +2611,7 @@ exports['noConflict - node only'] = function(test){
};
exports['concat'] = function(test){
+ test.expect(3);
var call_order = [];
var iterator = function (x, cb) {
setTimeout(function(){
@@ -2607,6 +2633,7 @@ exports['concat'] = function(test){
};
exports['concat error'] = function(test){
+ test.expect(1);
var iterator = function (x, cb) {
cb(new Error('test error'));
};
@@ -2617,6 +2644,7 @@ exports['concat error'] = function(test){
};
exports['concatSeries'] = function(test){
+ test.expect(3);
var call_order = [];
var iterator = function (x, cb) {
setTimeout(function(){
@@ -2638,8 +2666,9 @@ exports['concatSeries'] = function(test){
};
exports['until'] = function (test) {
- var call_order = [];
+ test.expect(3);
+ var call_order = [];
var count = 0;
async.until(
function () {
@@ -2668,6 +2697,8 @@ exports['until'] = function (test) {
};
exports['doUntil'] = function (test) {
+ test.expect(3);
+
var call_order = [];
var count = 0;
async.doUntil(
@@ -2696,6 +2727,8 @@ exports['doUntil'] = function (test) {
};
exports['doUntil callback params'] = function (test) {
+ test.expect(2);
+
var call_order = [];
var count = 0;
async.doUntil(
@@ -2724,6 +2757,8 @@ exports['doUntil callback params'] = function (test) {
};
exports['whilst'] = function (test) {
+ test.expect(3);
+
var call_order = [];
var count = 0;
@@ -2754,6 +2789,7 @@ exports['whilst'] = function (test) {
};
exports['doWhilst'] = function (test) {
+ test.expect(3);
var call_order = [];
var count = 0;
@@ -2783,8 +2819,8 @@ exports['doWhilst'] = function (test) {
};
exports['doWhilst callback params'] = function (test) {
+ test.expect(2);
var call_order = [];
-
var count = 0;
async.doWhilst(
function (cb) {
@@ -2814,6 +2850,8 @@ exports['doWhilst callback params'] = function (test) {
exports['queue'] = {
'queue': function (test) {
+ test.expect(17);
+
var call_order = [],
delays = [160,80,240,80];
@@ -2869,6 +2907,7 @@ exports['queue'] = {
},
'default concurrency': function (test) {
+ test.expect(17);
var call_order = [],
delays = [160,80,240,80];
@@ -2922,6 +2961,7 @@ exports['queue'] = {
},
'zero concurrency': function(test){
+ test.expect(1);
test.throws(function () {
async.queue(function (task, callback) {
callback(null, task);
@@ -2931,6 +2971,7 @@ exports['queue'] = {
},
'error propagation': function(test){
+ test.expect(1);
var results = [];
var q = async.queue(function (task, callback) {
@@ -2963,11 +3004,12 @@ exports['queue'] = {
// The original queue implementation allowed the concurrency to be changed only
// on the same event loop during which a task was added to the queue. This
-// test attempts to be a more rubust test.
+// test attempts to be a more robust test.
// Start with a concurrency of 1. Wait until a leter event loop and change
// the concurrency to 2. Wait again for a later loop then verify the concurrency.
// Repeat that one more time by chaning the concurrency to 5.
'changing concurrency': function (test) {
+ test.expect(3);
var q = async.queue(function(task, callback){
setTimeout(function(){
@@ -2997,6 +3039,7 @@ exports['queue'] = {
},
'push without callback': function (test) {
+ test.expect(1);
var call_order = [],
delays = [160,80,240,80];
@@ -3028,6 +3071,7 @@ exports['queue'] = {
},
'push with non-function': function (test) {
+ test.expect(1);
var q = async.queue(function () {}, 1);
test.throws(function () {
q.push({}, 1);
@@ -3036,6 +3080,7 @@ exports['queue'] = {
},
'unshift': function (test) {
+ test.expect(1);
var queue_order = [];
var q = async.queue(function (task, callback) {
@@ -3055,6 +3100,7 @@ exports['queue'] = {
},
'too many callbacks': function (test) {
+ test.expect(1);
var q = async.queue(function (task, callback) {
callback();
test.throws(function() {
@@ -3067,6 +3113,7 @@ exports['queue'] = {
},
'bulk task': function (test) {
+ test.expect(9);
var call_order = [],
delays = [160,80,240,80];
@@ -3103,6 +3150,7 @@ exports['queue'] = {
},
'idle': function(test) {
+ test.expect(7);
var q = async.queue(function (task, callback) {
// Queue is busy when workers are running
test.equal(q.idle(), false);
@@ -3128,6 +3176,7 @@ exports['queue'] = {
},
'pause': function(test) {
+ test.expect(3);
var call_order = [],
task_timeout = 100,
pause_timeout = 300,
@@ -3181,6 +3230,7 @@ exports['queue'] = {
},
'pause with concurrency': function(test) {
+ test.expect(4);
var call_order = [],
task_timeout = 100,
pause_timeout = 50,
@@ -3232,6 +3282,7 @@ exports['queue'] = {
},
'start paused': function (test) {
+ test.expect(2);
var q = async.queue(function (task, callback) {
setTimeout(function () {
callback();
@@ -3257,6 +3308,7 @@ exports['queue'] = {
},
'kill': function (test) {
+ test.expect(1);
var q = async.queue(function (task, callback) {
setTimeout(function () {
test.ok(false, "Function should never be called");
@@ -3278,6 +3330,7 @@ exports['queue'] = {
},
'events': function(test) {
+ test.expect(4);
var calls = [];
var q = async.queue(function(task, cb) {
// nop
@@ -3325,6 +3378,7 @@ exports['queue'] = {
},
'empty': function(test) {
+ test.expect(2);
var calls = [];
var q = async.queue(function(task, cb) {
// nop
@@ -3347,6 +3401,7 @@ exports['queue'] = {
},
'saturated': function (test) {
+ test.expect(1);
var saturatedCalled = false;
var q = async.queue(function(task, cb) {
async.setImmediate(cb);
@@ -3366,16 +3421,16 @@ exports['queue'] = {
},
'started': function(test) {
+ test.expect(2);
- var q = async.queue(function(task, cb) {
+ var q = async.queue(function(task, cb) {
cb(null, task);
- });
-
- test.equal(q.started, false);
- q.push([]);
- test.equal(q.started, true);
- test.done();
+ });
+ test.equal(q.started, false);
+ q.push([]);
+ test.equal(q.started, true);
+ test.done();
}
};
@@ -3384,6 +3439,7 @@ exports['queue'] = {
exports['priorityQueue'] = {
'priorityQueue': function (test) {
+ test.expect(17);
var call_order = [];
// order of completion: 2,1,4,3
@@ -3433,7 +3489,8 @@ exports['priorityQueue'] = {
};
},
-' concurrency': function (test) {
+'concurrency': function (test) {
+ test.expect(17);
var call_order = [],
delays = [160,80,240,80];
@@ -3494,6 +3551,7 @@ exports['priorityQueue'] = {
exports['cargo'] = {
'cargo': function (test) {
+ test.expect(19);
var call_order = [],
delays = [160, 160, 80];
@@ -3560,6 +3618,7 @@ exports['cargo'] = {
},
'without callback': function (test) {
+ test.expect(1);
var call_order = [],
delays = [160,80,240,80];
@@ -3596,6 +3655,7 @@ exports['cargo'] = {
},
'bulk task': function (test) {
+ test.expect(7);
var call_order = [],
delays = [120,40];
@@ -3628,41 +3688,43 @@ exports['cargo'] = {
},
'drain once': function (test) {
+ test.expect(1);
- var c = async.cargo(function (tasks, callback) {
+ var c = async.cargo(function (tasks, callback) {
callback();
}, 3);
var drainCounter = 0;
c.drain = function () {
- drainCounter++;
+ drainCounter++;
};
for(var i = 0; i < 10; i++){
- c.push(i);
+ c.push(i);
}
setTimeout(function(){
- test.equal(drainCounter, 1);
- test.done();
+ test.equal(drainCounter, 1);
+ test.done();
}, 500);
},
'drain twice': function (test) {
+ test.expect(1);
var c = async.cargo(function (tasks, callback) {
- callback();
+ callback();
}, 3);
var loadCargo = function(){
- for(var i = 0; i < 10; i++){
- c.push(i);
- }
+ for(var i = 0; i < 10; i++){
+ c.push(i);
+ }
};
var drainCounter = 0;
c.drain = function () {
- drainCounter++;
+ drainCounter++;
};
loadCargo();
@@ -3675,6 +3737,7 @@ exports['cargo'] = {
},
'events': function(test) {
+ test.expect(4);
var calls = [];
var q = async.cargo(function(task, cb) {
// nop
@@ -3899,6 +3962,7 @@ exports['memoize'] = {
exports['ensureAsync'] = {
'defer sync functions': function (test) {
+ test.expect(6);
var sync = true;
async.ensureAsync(function (arg1, arg2, cb) {
test.equal(arg1, 1);
@@ -3915,6 +3979,7 @@ exports['ensureAsync'] = {
},
'do not defer async functions': function (test) {
+ test.expect(6);
var sync = false;
async.ensureAsync(function (arg1, arg2, cb) {
test.equal(arg1, 1);
@@ -3934,6 +3999,7 @@ exports['ensureAsync'] = {
},
'double wrapping': function (test) {
+ test.expect(6);
var sync = true;
async.ensureAsync(async.ensureAsync(function (arg1, arg2, cb) {
test.equal(arg1, 1);