Permalink
Browse files

reorganize tests a little

  • Loading branch information...
1 parent 41e35e7 commit a5eea42f32dfe7d165069ae983a3a8251ff649f6 @bkw bkw committed Oct 16, 2012
Showing with 258 additions and 176 deletions.
  1. +1 −1 Makefile
  2. +49 −35 test/test-addtask.js
  3. +27 −19 test/test-args.js
  4. +33 −21 test/test-basic.js
  5. +14 −12 test/test-bind.js
  6. +33 −22 test/test-callback-arguments.js
  7. +14 −11 test/test-defaultobject.js
  8. +58 −38 test/test-events.js
  9. +8 −5 test/test-exports.js
  10. +6 −3 test/test-packagejson.js
  11. +15 −9 test/test-return.js
View
@@ -1,6 +1,6 @@
default: test
test:
- @./node_modules/.bin/mocha --ui bdd --reporter list test/*
+ @./node_modules/.bin/mocha --ui bdd # --reporter spec
.PHONY: test
View
@@ -1,42 +1,56 @@
-var should = require('should'),
- delayPool = require('../lib/poolr.js').createPool(2),
- called = 0,
- running = 0;
-
-
-var randomSleep = function(payload, callback) {
- called ++;
- running ++;
- running.should.be.below(3);
- var args = Array.prototype.slice.call(arguments);
-
- var delay = Math.ceil(Math.random() * 500);
- setTimeout(function(){ running--; return callback(null, payload); }, delay);
-}
-
-describe('poolr', function() {
- describe('with limit two', function() {
- it('should not run more than two tasks', function(done) {
- var outstanding = 0;
- for (var i=0; i<10; i++) {
- outstanding++;
- (function(i){
+/*global describe:true, it:true */
+'use strict';
+var should = require('should');
+
+describe('poolr', function () {
+
+ describe('with limit two', function () {
+ var delayPool = require('../lib/poolr.js').createPool(2),
+ called = 0,
+ running = 0,
+
+ randomSleep = function (payload, callback) {
+ var args = Array.prototype.slice.call(arguments),
+ delay = Math.ceil(Math.random() * 500);
+ called ++;
+ running ++;
+ running.should.be.below(3);
+ setTimeout(function () {
+ running--;
+ return callback(null, payload);
+ }, delay);
+ };
+
+
+ it('should not run more than two tasks', function (done) {
+ var outstanding = 0, i,
+ check1 = function (i) {
+ running.should.be.below(3);
+ return delayPool.addTask(randomSleep, i, check2);
+ },
+ check2 = function (err, res) {
running.should.be.below(3);
- return delayPool.addTask(randomSleep, i, function(err, res){
- running.should.be.below(3);
- if (--outstanding === 0) {
- done();
- }
- });
- })(i);
+ if (--outstanding === 0) {
+ done();
+ }
+ };
+
+ for (i = 0; i < 10; i++) {
+ outstanding++;
+ check1(i, check2);
}
});
- it('should have been called 10 times', function(done) {
- delayPool._addTask(function(cb){return cb(null);},function(dummy) {
- called.should.eql(10);
- done();
- });
+ it('should have been called 10 times', function (done) {
+ delayPool._addTask(
+ function (cb) {
+ return cb(null);
+ },
+ function (dummy) {
+ called.should.eql(10);
+ done();
+ }
+ );
});
});
});
View
@@ -1,34 +1,42 @@
+/*global describe:true, it:true */
+'use strict';
var should = require('should'),
- poolr = require('../lib/poolr.js'),
- called = 0,
- running = 0;
+ poolr = require('../lib/poolr.js');
+describe('poolr', function () {
+ describe('taskArguments', function () {
+ var testPool = poolr.createPool(5),
+ called = 0,
+ running = 0,
-var checkArg = function(payload, callback) {
- payload.should.eql(called++);
- running ++;
- process.nextTick(function(){return callback(null, payload)});
-}
+ checkArg = function (payload, callback) {
+ payload.should.eql(called++);
+ running ++;
+ process.nextTick(function () {
+ return callback(null, payload);
+ });
+ };
-describe('poolr', function() {
- var testPool = poolr.createPool(5);
- describe('taskArguments', function() {
- it('should be dispatched', function(done) {
- var outstanding = 0;
- for (var i=0; i<10; i++) {
- outstanding++;
- (function(i){
+ it('should be dispatched', function (done) {
+ var outstanding = 0, i,
+ check = function (i) {
testPool._addTask(
- function(callback) { return checkArg(i, callback); },
- function(err, res) {
+ function (callback) {
+ return checkArg(i, callback);
+ },
+ function (err, res) {
res.should.eql(i);
if (--outstanding === 0) {
done();
}
}
);
- })(i);
+ };
+
+ for (i = 0; i < 10; i++) {
+ outstanding++;
+ check(i);
}
});
});
View
@@ -1,28 +1,40 @@
+/*global describe:true, it:true */
+'use strict';
var should = require('should'),
- delayPool = require('../lib/poolr.js').createPool(5),
- called = 0;
+ poolr = require('../lib/poolr.js');
-var randomSleep = function(callback) {
- called ++;
- var delay = Math.ceil(Math.random() * 200);
- setTimeout(function(){
- callback(null, 'returning after ' + delay/1000 + ' secs.');
- }, delay);
-}
+describe('poolr with limit 5', function () {
+ var delayPool = poolr.createPool(5),
+ called = 0;
-describe('poolr with limit 5', function() {
- it('should call all tasks', function(done) {
- var outstanding = 0;
- for (var i=0; i<10; i++) {
- outstanding++;
- (function(i){
- delayPool._addTask(randomSleep, function(err, res) {
- if (--outstanding === 0) {
- called.should.eql(10);
- done();
+
+
+ it('should call all tasks', function (done) {
+ var outstanding = 0, i,
+ check = function (i) {
+ delayPool._addTask(
+ function (callback) {
+ called ++;
+ var delay = Math.ceil(Math.random() * 200);
+ setTimeout(function () {
+ callback(
+ null,
+ 'returning after ' + delay / 1000 + ' secs.'
+ );
+ }, delay);
+ },
+ function (err, res) {
+ if (--outstanding === 0) {
+ called.should.eql(10);
+ done();
+ }
}
- });
- })(i);
+ );
+ };
+
+ for (i = 0; i < 10; i++) {
+ outstanding++;
+ check(i);
}
});
});
View
@@ -1,23 +1,25 @@
-var should = require('should'),
- poolr = require('../lib/poolr.js').createPool;
+/*global describe:true, it:true */
+'use strict';
+var should = require('should'),
+ poolr = require('../lib/poolr.js').createPool,
+ someClass;
-var someClass = function(someval) {
+someClass = function (someval) {
this.state = someval;
-}
-
+};
someClass.prototype.someFunc = function (someArg, callback) {
return callback(this.state, someArg);
-}
+};
-describe('poolr', function() {
- var myPool = poolr(1);
+describe('poolr', function () {
- describe('method context', function() {
- var obj = new someClass('foo');
+ describe('method context', function () {
+ var myPool = poolr(1),
+ obj = new someClass('foo');
- it('should be preserved when using bind()', function(done) {
- myPool.addTask(obj.someFunc.bind(obj), 'bar', function(err, res) {
+ it('should be preserved when using bind()', function (done) {
+ myPool.addTask(obj.someFunc.bind(obj), 'bar', function (err, res) {
err.should.eql('foo');
res.should.eql('bar');
done();
@@ -1,28 +1,39 @@
-var should = require('should')
- , poolr = require('../lib/poolr.js')
- , testfunc = function(i,callback) {
- process.nextTick(function(){return callback(i,i+1,i+2)});
- }
- ;
+/*global describe:true, it:true */
+'use strict';
-describe('poolr', function() {
- var testPool = poolr.createPool(5);
- describe('callbacks', function() {
- it('should be called with correct arguments', function(done) {
- var outstanding = 0;
+var should = require('should'),
+ poolr = require('../lib/poolr.js');
- for (var i=0; i<10; i++) {
- outstanding++;
- (function(i){
- testPool.addTask(testfunc,i,function(a,b,c) {
- a.should.eql(i);
- b.should.eql(i+1);
- c.should.eql(i+2);
- if (--outstanding === 0) {
- done();
+
+describe('poolr', function () {
+ describe('callbacks', function () {
+ var testPool = poolr.createPool(5),
+ testfunc = function (i, callback) {
+ process.nextTick(function () {
+ return callback(i, i + 1, i + 2);
+ });
+ };
+
+ it('should be called with correct arguments', function (done) {
+ var outstanding = 0, i,
+ check = function (i) {
+ testPool.addTask(
+ testfunc,
+ i,
+ function (a, b, c) {
+ a.should.eql(i);
+ b.should.eql(i + 1);
+ c.should.eql(i + 2);
+ if (--outstanding === 0) {
+ done();
+ }
}
- });
- })(i);
+ );
+ };
+
+ for (i = 0; i < 10; i++) {
+ outstanding++;
+ check(i);
}
});
});
View
@@ -1,20 +1,23 @@
+/*global describe:true, it:true */
+'use strict';
+
var should = require('should'),
- poolr = require('../lib/poolr.js').createPool;
+ poolr = require('../lib/poolr.js').createPool,
+ SomeClass;
-var someClass = function(someval) {
+SomeClass = function (someval) {
this.state = someval;
-}
-
-someClass.prototype.someFunc = function (someArg, callback) {
+};
+SomeClass.prototype.someFunc = function (someArg, callback) {
return callback(this.state, someArg);
-}
+};
-describe('poolr default object', function() {
- var obj = new someClass('foo');
- var myPool = poolr(1, obj);
- it('should preserve method context', function(done) {
- myPool.addTask(obj.someFunc, 'bar', function(err, res) {
+describe('poolr default object', function () {
+ var obj = new SomeClass('foo'),
+ myPool = poolr(1, obj);
+ it('should preserve method context', function (done) {
+ myPool.addTask(obj.someFunc, 'bar', function (err, res) {
err.should.eql('foo');
res.should.eql('bar');
done();
Oops, something went wrong.

0 comments on commit a5eea42

Please sign in to comment.