Permalink
Browse files

ported nest test to tap

  • Loading branch information...
1 parent c853eca commit 55e724bca85d2301a21e0577c0fecdb90ddf8b95 @substack committed Apr 16, 2012
Showing with 105 additions and 146 deletions.
  1. +6 −0 package.json
  2. +54 −145 test/chainsaw.js
  3. +1 −1 test/getset.js
  4. +44 −0 test/nest.js
View
@@ -10,6 +10,12 @@
"dependencies" : {
"traverse" : ">=0.3.0 <0.4"
},
+ "devDependencies" : {
+ "tap" : "~0.2.4"
+ },
+ "scripts" : {
+ "test" : "tap test/*.js"
+ },
"keywords" : [
"chain",
"fluent",
View
@@ -1,101 +1,10 @@
-var assert = require('assert');
-var Chainsaw = require('../index');
+var test = require('tap').test;
+var chainsaw = require('../');
-exports.getset = function () {
- var to = setTimeout(function () {
- assert.fail('builder never fired');
- }, 1000);
-
- var ch = Chainsaw(function (saw) {
- clearTimeout(to);
- var num = 0;
-
- this.get = function (cb) {
- cb(num);
- saw.next();
- };
-
- this.set = function (n) {
- num = n;
- saw.next();
- };
-
- var ti = setTimeout(function () {
- assert.fail('end event not emitted');
- }, 50);
-
- saw.on('end', function () {
- clearTimeout(ti);
- assert.equal(times, 3);
- });
- });
-
- var times = 0;
- ch
- .get(function (x) {
- assert.equal(x, 0);
- times ++;
- })
- .set(10)
- .get(function (x) {
- assert.equal(x, 10);
- times ++;
- })
- .set(20)
- .get(function (x) {
- assert.equal(x, 20);
- times ++;
- })
- ;
-};
-
-exports.nest = function () {
- var ch = (function () {
- var vars = {};
- return Chainsaw(function (saw) {
- this.do = function (cb) {
- saw.nest(cb, vars);
- };
- });
- })();
-
- var order = [];
- var to = setTimeout(function () {
- assert.fail("Didn't get to the end");
- }, 50);
-
- ch
- .do(function (vars) {
- vars.x = 'y';
- order.push(1);
-
- this
- .do(function (vs) {
- order.push(2);
- vs.x = 'x';
- })
- .do(function (vs) {
- order.push(3);
- vs.z = 'z';
- })
- ;
- })
- .do(function (vars) {
- vars.y = 'y';
- order.push(4);
- })
- .do(function (vars) {
- assert.eql(order, [1,2,3,4]);
- assert.eql(vars, { x : 'x', y : 'y', z : 'z' });
- clearTimeout(to);
- })
- ;
-};
-
-exports.nestWait = function () {
+test('nestWait', function (t) {
var ch = (function () {
var vars = {};
- return Chainsaw(function (saw) {
+ return chainsaw(function (saw) {
this.do = function (cb) {
saw.nest(cb, vars);
};
@@ -110,7 +19,7 @@ exports.nestWait = function () {
var order = [];
var to = setTimeout(function () {
- assert.fail("Didn't get to the end");
+ t.fail("Didn't get to the end");
}, 1000);
var times = {};
@@ -133,7 +42,7 @@ exports.nestWait = function () {
times.z = Date.now();
var dt = times.z - times.x;
- assert.ok(dt >= 50 && dt < 75);
+ t.ok(dt >= 50 && dt < 75);
})
;
})
@@ -145,21 +54,21 @@ exports.nestWait = function () {
})
.wait(100)
.do(function (vars) {
- assert.eql(order, [1,2,3,4]);
- assert.eql(vars, { x : 'x', y : 'y', z : 'z' });
+ t.same(order, [1,2,3,4]);
+ t.same(vars, { x : 'x', y : 'y', z : 'z' });
clearTimeout(to);
times.end = Date.now();
var dt = times.end - times.y;
- assert.ok(dt >= 100 && dt < 125)
+ t.ok(dt >= 100 && dt < 125)
})
;
-};
+});
-exports.nestNext = function () {
+test('nestNext', function (t) {
var ch = (function () {
var vars = {};
- return Chainsaw(function (saw) {
+ return chainsaw(function (saw) {
this.do = function (cb) {
saw.nest(false, function () {
var args = [].slice.call(arguments);
@@ -172,7 +81,7 @@ exports.nestNext = function () {
var order = [];
var to = setTimeout(function () {
- assert.fail("Didn't get to the end");
+ t.fail("Didn't get to the end");
}, 500);
var times = [];
@@ -204,47 +113,47 @@ exports.nestNext = function () {
setTimeout(next, 5);
})
.do(function (vars) {
- assert.eql(order, [1,2,3,4]);
- assert.eql(vars, { x : 'x', y : 'y', z : 'z' });
+ t.same(order, [1,2,3,4]);
+ t.same(vars, { x : 'x', y : 'y', z : 'z' });
clearTimeout(to);
})
;
-};
+});
-exports.builder = function () {
- var cx = Chainsaw(function (saw) {
+test('builder', function (t) {
+ var cx = chainsaw(function (saw) {
this.x = function () {};
});
- assert.ok(cx.x);
+ t.ok(cx.x);
- var cy = Chainsaw(function (saw) {
+ var cy = chainsaw(function (saw) {
return { y : function () {} };
});
- assert.ok(cy.y);
+ t.ok(cy.y);
- var cz = Chainsaw(function (saw) {
+ var cz = chainsaw(function (saw) {
return { z : function (cb) { saw.nest(cb) } };
});
- assert.ok(cz.z);
+ t.ok(cz.z);
var to = setTimeout(function () {
- assert.fail("Nested z didn't run");
+ t.fail("Nested z didn't run");
}, 50);
cz.z(function () {
clearTimeout(to);
- assert.ok(this.z);
+ t.ok(this.z);
});
-};
+});
-this.attr = function () {
+test('attr', function (t) {
var to = setTimeout(function () {
- assert.fail("attr chain didn't finish");
+ t.fail("attr chain didn't finish");
}, 50);
var xy = [];
- var ch = Chainsaw(function (saw) {
+ var ch = chainsaw(function (saw) {
this.h = {
x : function () {
xy.push('x');
@@ -253,22 +162,22 @@ this.attr = function () {
y : function () {
xy.push('y');
saw.next();
- assert.eql(xy, ['x','y']);
+ t.same(xy, ['x','y']);
clearTimeout(to);
}
};
});
- assert.ok(ch.h);
- assert.ok(ch.h.x);
- assert.ok(ch.h.y);
+ t.ok(ch.h);
+ t.ok(ch.h.x);
+ t.ok(ch.h.y);
ch.h.x().h.y();
-};
+});
-exports.down = function () {
+test('down', function (t) {
var error = null;
var s;
- var ch = Chainsaw(function (saw) {
+ var ch = chainsaw(function (saw) {
s = saw;
this.raise = function (err) {
error = err;
@@ -289,28 +198,28 @@ exports.down = function () {
});
var to = setTimeout(function () {
- assert.fail(".do() after .catch() didn't fire");
+ t.fail(".do() after .catch() didn't fire");
}, 50);
ch
.do(function () {
this.raise('pow');
})
.do(function () {
- assert.fail("raise didn't skip over this do block");
+ t.fail("raise didn't skip over this do block");
})
.catch(function (err) {
- assert.equal(err, 'pow');
+ t.equal(err, 'pow');
})
.do(function () {
clearTimeout(to);
})
;
-};
+});
-exports.trap = function () {
+test('trap', function (t) {
var error = null;
- var ch = Chainsaw(function (saw) {
+ var ch = chainsaw(function (saw) {
var pars = 0;
var stack = [];
var i = 0;
@@ -354,10 +263,10 @@ exports.trap = function () {
});
var to = setTimeout(function () {
- assert.fail(".do() after .join() didn't fire");
+ t.fail(".do() after .join() didn't fire");
}, 100);
var tj = setTimeout(function () {
- assert.fail('.join() never fired');
+ t.fail('.join() never fired');
}, 100);
var joined = false;
@@ -369,27 +278,27 @@ exports.trap = function () {
setTimeout(this.bind(null, 2), 25);
})
.join(function (x, y) {
- assert.equal(x[0], 1);
- assert.equal(y[0], 2);
+ t.equal(x[0], 1);
+ t.equal(y[0], 2);
clearTimeout(tj);
joined = true;
})
.do(function () {
clearTimeout(to);
- assert.ok(joined);
+ t.ok(joined);
})
;
-};
+});
-exports.jump = function () {
+test('jump', function (t) {
var to = setTimeout(function () {
- assert.fail('builder never fired');
+ t.fail('builder never fired');
}, 50);
var xs = [ 4, 5, 6, -4, 8, 9, -1, 8 ];
var xs_ = [];
- var ch = Chainsaw(function (saw) {
+ var ch = chainsaw(function (saw) {
this.x = function (i) {
xs_.push(i);
saw.next();
@@ -403,8 +312,8 @@ exports.jump = function () {
saw.on('end', function () {
clearTimeout(to);
- assert.eql(xs, [ 8 ]);
- assert.eql(xs_, [ 1, 1, 1, 1, 2, 3, 2, 3, 2, 3 ]);
+ t.same(xs, [ 8 ]);
+ t.same(xs_, [ 1, 1, 1, 1, 2, 3, 2, 3, 2, 3 ]);
});
});
@@ -415,4 +324,4 @@ exports.jump = function () {
.x(3)
.y(2)
;
-};
+});
View
@@ -1,5 +1,5 @@
var test = require('tap').test;
-var chainsaw = require('../index');
+var chainsaw = require('../');
test('getset', function (t) {
t.plan(4);
Oops, something went wrong.

0 comments on commit 55e724b

Please sign in to comment.