Skip to content

Commit

Permalink
simple test using tap
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 3, 2011
1 parent de1ab08 commit b2e69af
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions test/simple.js
@@ -1,37 +1,39 @@
var dnode = require('../');
var assert = require('assert');
var test = require('tap').test;

exports.simple = function () {
test('simple', function (t) {
t.plan(7);
var port = Math.floor(Math.random() * 40000 + 10000);

var server = dnode({
timesTen : function (n,reply) {
assert.equal(n, 50);
t.equal(n, 50);
reply(n * 10);
},
moo : function (reply) { reply(100) },
sTimesTen : function (n, cb) {
assert.equal(n, 5);
t.equal(n, 5);
cb(n * 10);
},
}).listen(port.toString()); // test for stringified ports too why not

server.on('ready', function () {
dnode.connect(port, function (remote, conn) {
assert.ok(conn.id);
assert.equal(conn.stream.remoteAddress, '127.0.0.1');
t.ok(conn.id);
t.equal(conn.stream.remoteAddress, '127.0.0.1');

remote.moo(function (x) {
assert.equal(x, 100, 'remote moo == 100');
t.equal(x, 100, 'remote moo == 100');
});
remote.sTimesTen(5, function (m) {
assert.equal(m, 50, '5 * 10 == 50');
t.equal(m, 50, '5 * 10 == 50');
remote.timesTen(m, function (n) {
assert.equal(n, 500, '50 * 10 == 500');
t.equal(n, 500, '50 * 10 == 500');
conn.end();
server.close();
t.end();
});
});
});
});
};
});

0 comments on commit b2e69af

Please sign in to comment.