Permalink
Browse files

now using tap for all the tests

  • Loading branch information...
1 parent 9519546 commit 8f485328a0b4441a54116d8cf1aad4560e48fa4d @substack committed Jan 21, 2012
Showing with 101 additions and 114 deletions.
  1. +4 −1 package.json
  2. +12 −10 test/args.js
  3. +20 −36 test/fn.js
  4. +17 −28 test/proto.js
  5. +35 −27 test/scrub.js
  6. +13 −12 test/store.js
View
@@ -13,8 +13,11 @@
"traverse" : "0.5.x",
"jsonify" : "0.0.x"
},
+ "devDependencies" : {
+ "tap" : "0.1.x"
+ },
"scripts": {
- "test": "expresso"
+ "test": "tap test/*.js"
},
"engines": { "node" : ">=0.2.0" }
}
View
@@ -1,45 +1,45 @@
-var assert = require('assert');
+var test = require('tap').test;
var protocol = require('../');
function argv () { return arguments }
-exports.args = function () {
- assert.eql(
+test('args', function (t) {
+ t.deepEqual(
protocol.parseArgs(argv('moo.com', 555)),
{ host : 'moo.com', port : 555 }
);
- assert.eql(
+ t.deepEqual(
protocol.parseArgs(argv('7777')),
{ port : 7777 }
);
- assert.eql(
+ t.deepEqual(
protocol.parseArgs(argv({
host : 'moosy.moo.com',
port : 5050,
})),
{ host : 'moosy.moo.com', port : 5050 }
);
- assert.eql(
+ t.deepEqual(
protocol.parseArgs(argv('meow.cats.com', { port : '1234', })),
{ host : 'meow.cats.com', port : 1234 }
);
- assert.eql(
+ t.deepEqual(
typeof protocol.parseArgs(argv('789')).port,
'number'
);
- assert.eql(
+ t.deepEqual(
protocol.parseArgs(argv(
{ host : 'woof.dogs.com' }, { port : 4050 }
)),
{ host : 'woof.dogs.com', port : 4050 }
);
- assert.eql(
+ t.deepEqual(
protocol.parseArgs(argv(
undefined,
{ host : 'woof.dogs.com' },
@@ -49,4 +49,6 @@ exports.args = function () {
)),
{ host : 'woof.dogs.com', port : 4050 }
);
-};
+
+ t.end();
+});
View
@@ -1,20 +1,17 @@
-var assert = require('assert');
+var test = require('tap').test;
var proto = require('../');
-var Traverse = require('traverse');
+var traverse = require('traverse');
var EventEmitter = require('events').EventEmitter;
-exports.protoFn = function () {
+test('protoFn', function (t) {
+ t.plan(11);
+
var server = proto(function (remote, conn) {
- assert.ok(conn);
- assert.ok(conn instanceof EventEmitter);
-
- var tr = setTimeout(function () {
- assert.fail('never got ready event');
- }, 5000);
+ t.ok(conn);
+ t.ok(conn instanceof EventEmitter);
conn.on('ready', function () {
- clearTimeout(tr);
- assert.eql(remote, { a : 1, b : 2 });
+ t.deepEqual(remote, { a : 1, b : 2 });
});
this.x = function (f, g) {
@@ -31,27 +28,19 @@ exports.protoFn = function () {
var sreqs = [];
s.on('request', function (req) {
- sreqs.push(Traverse.clone(req));
+ sreqs.push(traverse.clone(req));
c.handle(req);
});
var creqs = [];
c.on('request', function (req) {
- creqs.push(Traverse.clone(req));
+ creqs.push(traverse.clone(req));
s.handle(req);
});
- var tf = setTimeout(function () {
- assert.fail('never called f');
- }, 5000);
-
- var tg = setTimeout(function () {
- assert.fail('never called g');
- }, 5000);
-
s.start();
- assert.eql(sreqs, [ {
+ t.deepEqual(sreqs, [ {
method : 'methods',
arguments : [ { x : '[Function]', y : 555 } ],
callbacks : { 0 : [ '0', 'x' ] },
@@ -60,7 +49,7 @@ exports.protoFn = function () {
c.start();
- assert.eql(creqs, [ {
+ t.deepEqual(creqs, [ {
method : 'methods',
arguments : [ { a : 1, b : 2 } ],
callbacks : {},
@@ -69,30 +58,25 @@ exports.protoFn = function () {
c.request('x', [
function (x, y , z) {
- clearTimeout(tf);
- assert.eql([ x, y, z ], [ 7, 8, 9 ]);
+ t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
},
function (qr) {
- clearTimeout(tg);
- assert.eql(qr, [ 'q', 'r' ]);
+ t.deepEqual(qr, [ 'q', 'r' ]);
}
]);
- assert.eql(creqs.slice(1), [ {
+ t.deepEqual(creqs.slice(1), [ {
method : 'x',
arguments : [ '[Function]', '[Function]' ],
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
links : [],
} ]);
- var tt = setTimeout(function () {
- assert.fail('broken json never emitted an error');
- }, 5000);
c.on('error', function (err) {
- clearTimeout(tt);
- assert.ok(err.stack);
- assert.ok(err.message.match(/^Error parsing JSON/));
- assert.ok(err instanceof SyntaxError);
+ t.ok(err.stack);
+ t.ok(err.message.match(/^Error parsing JSON/));
+ t.ok(err instanceof SyntaxError);
+ t.end();
});
c.parse('{');
-};
+});
View
@@ -1,8 +1,10 @@
-var assert = require('assert');
+var test = require('tap').test;
var proto = require('../');
-var Traverse = require('traverse');
+var traverse = require('traverse');
-exports.protoHashes = function () {
+test('proto hashes', function (t) {
+ t.plan(7);
+
var server = proto({
x : function (f, g) {
setTimeout(f.bind({}, 7, 8, 9), 50);
@@ -18,27 +20,19 @@ exports.protoHashes = function () {
var sreqs = [];
s.on('request', function (req) {
- sreqs.push(Traverse.clone(req));
+ sreqs.push(traverse.clone(req));
c.handle(req);
});
var creqs = [];
c.on('request', function (req) {
- creqs.push(Traverse.clone(req));
+ creqs.push(traverse.clone(req));
s.handle(req);
});
- var tf = setTimeout(function () {
- assert.fail('never called f');
- }, 5000);
-
- var tg = setTimeout(function () {
- assert.fail('never called g');
- }, 5000);
-
s.start();
- assert.eql(sreqs, [ {
+ t.deepEqual(sreqs, [ {
method : 'methods',
arguments : [ { x : '[Function]', y : 555 } ],
callbacks : { 0 : [ '0', 'x' ] },
@@ -47,7 +41,7 @@ exports.protoHashes = function () {
c.start();
- assert.eql(creqs, [ {
+ t.deepEqual(creqs, [ {
method : 'methods',
arguments : [ {} ],
callbacks : {},
@@ -56,30 +50,25 @@ exports.protoHashes = function () {
c.request('x', [
function (x, y , z) {
- clearTimeout(tf);
- assert.eql([ x, y, z ], [ 7, 8, 9 ]);
+ t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
},
function (qr) {
- clearTimeout(tg);
- assert.eql(qr, [ 'q', 'r' ]);
+ t.deepEqual(qr, [ 'q', 'r' ]);
}
]);
- assert.eql(creqs.slice(1), [ {
+ t.deepEqual(creqs.slice(1), [ {
method : 'x',
arguments : [ '[Function]', '[Function]' ],
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
links : [],
} ]);
- var tt = setTimeout(function () {
- assert.fail('broken json never emitted an error');
- }, 5000);
c.on('error', function (err) {
- clearTimeout(tt);
- assert.ok(err.stack);
- assert.ok(err.message.match(/^Error parsing JSON/));
- assert.ok(err instanceof SyntaxError);
+ t.ok(err.stack);
+ t.ok(err.message.match(/^Error parsing JSON/));
+ t.ok(err instanceof SyntaxError);
+ t.end();
});
c.parse('{');
-};
+});
Oops, something went wrong.

0 comments on commit 8f48532

Please sign in to comment.