Comparing version 0.8.2 to 0.9.0
var protocol = require('dnode-protocol'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var io = require('./socket.io').io; | ||
var io = require('socket.io-client'); | ||
var json = typeof JSON === 'object' ? JSON : require('jsonify'); | ||
@@ -26,6 +27,7 @@ var exports = module.exports = dnode; | ||
if (!params.port) params.port = parseInt(window.location.port, 10); | ||
if (isNaN(params.port)) delete params.port; | ||
var sock = client.socketio = new io.Socket( | ||
params.host || window.location.hostname, | ||
var proto = (params.proto || window.location.protocol) | ||
.replace(/:.*/, '') + '://'; | ||
var sock = client.socketio = io.connect( | ||
proto + (params.host || window.location.host), | ||
params | ||
@@ -51,3 +53,3 @@ ); | ||
client.on('request', function (req) { | ||
sock.send(JSON.stringify(req) + '\n'); | ||
sock.send(json.stringify(req) + '\n'); | ||
}); | ||
@@ -64,4 +66,2 @@ | ||
}); | ||
sock.connect(); | ||
}; | ||
@@ -68,0 +68,0 @@ |
@@ -1,5 +0,5 @@ | ||
var $ = require('jquery'); | ||
var $ = require('jquery-browserify'); | ||
var dnode = require('dnode'); | ||
$(window).ready(function () { | ||
$(document).ready(function () { | ||
// Fetch the user's name before the main chat code fires | ||
@@ -6,0 +6,0 @@ $('form#name').submit(function (ev) { |
@@ -8,9 +8,3 @@ // simple dnode chat server with browserify | ||
var browserify = require('browserify'); | ||
app.use(browserify({ | ||
require : [ | ||
'dnode', | ||
{ jquery : 'jquery-browserify' } | ||
], | ||
entry : __dirname + '/entry.js' | ||
})); | ||
app.use(browserify(__dirname + '/entry.js', { watch : true })); | ||
@@ -25,3 +19,3 @@ app.listen(6061); | ||
var dnode = require('dnode'); | ||
var dnode = require('../../'); | ||
dnode(ChatServer).listen(app); | ||
@@ -43,3 +37,5 @@ | ||
evNames.forEach(function (name) { | ||
emitter.removeListener(name, client[name]); | ||
if (typeof client[name] === 'function') { | ||
emitter.removeListener(name, client[name]); | ||
} | ||
}); | ||
@@ -46,0 +42,0 @@ emitter.emit('parted', client.name); |
@@ -130,2 +130,3 @@ var net = require('net'); | ||
dnode.prototype.listen = function () { | ||
var self = this; | ||
var params = protocol.parseArgs(arguments); | ||
@@ -191,7 +192,7 @@ var server = params.server; | ||
server.on(listenFor, (function (stream) { | ||
var client = createClient(this.proto, stream); | ||
server.on(listenFor, function (stream) { | ||
var client = createClient(self.proto, stream); | ||
clients[client.id] = client; | ||
this.stack.forEach(function (middleware) { | ||
self.stack.forEach(function (middleware) { | ||
middleware.call(client.instance, client.remote, client); | ||
@@ -207,3 +208,3 @@ }); | ||
client.start(); | ||
}).bind(this)); | ||
}); | ||
@@ -210,0 +211,0 @@ this.server = server; |
var EventEmitter = require('events').EventEmitter; | ||
var Stream = require('stream').Stream; | ||
var io = require('socket.io'); | ||
@@ -50,2 +51,6 @@ var fs = require('fs'); | ||
module.exports = function (webserver, mount, ioOptions) { | ||
if (ioOptions['log level'] === undefined) { | ||
ioOptions['log level'] = -1; | ||
} | ||
var sock = io.listen(webserver, ioOptions); | ||
@@ -76,4 +81,5 @@ var server = new EventEmitter; | ||
sock.on('connection', function (client) { | ||
var stream = new EventEmitter; | ||
sock.sockets.on('connection', function (client) { | ||
var stream = new Stream; | ||
stream.socketio = client; | ||
@@ -84,4 +90,4 @@ stream.readable = true; | ||
stream.write = client.send.bind(client); | ||
stream.end = client.connection.end.bind(client.connection); | ||
stream.destroy = client.connection.destroy.bind(client.connection); | ||
stream.end = stream.destroy | ||
= client.disconnect.bind(client.disconnect); | ||
@@ -88,0 +94,0 @@ client.on('message', stream.emit.bind(stream, 'data')); |
{ | ||
"name" : "dnode", | ||
"version" : "0.8.2", | ||
"version" : "0.9.0", | ||
"description" : "freestyle RPC", | ||
@@ -25,12 +25,16 @@ "main" : "./index.js", | ||
"dependencies" : { | ||
"socket.io" : ">=0.6.1 <0.7", | ||
"socket.io" : "https://github.com/substack/socket.io-client/tarball/master", | ||
"lazy" : ">=1.0.5 <1.1", | ||
"traverse" : "0.4.x", | ||
"dnode-protocol" : ">=0.0.12 <0.1" | ||
"dnode-protocol" : "0.1.x", | ||
"jsonify" : "0.0.x" | ||
}, | ||
"devDependencies" : { | ||
"expresso" : "0.7.x", | ||
"tap" : "0.0.x", | ||
"browserify" : "1.4.x", | ||
"uglify-js" : "1.0.6" | ||
}, | ||
"scripts" : { | ||
"test" : "tap test/*.js" | ||
}, | ||
"browserify" : "browser/index.js", | ||
@@ -37,0 +41,0 @@ "engine" : { |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports._id = function () { | ||
test('_id', function (t) { | ||
t.plan(1); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -11,7 +12,8 @@ | ||
dnode.connect(port, function (remote, conn) { | ||
assert.eql(remote._id, 1337); | ||
t.equal(remote._id, 1337); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports['bidirectional'] = function () { | ||
test('bidirectional', function (t) { | ||
t.plan(5); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var counts = { timesX : 0, clientX : 0, x : 0 }; | ||
@@ -11,6 +11,6 @@ | ||
this.timesX = function (n,f) { | ||
assert.equal(n, 3, "timesX's n == 3"); | ||
t.equal(n, 3, "timesX's n == 3"); | ||
counts.timesX ++; | ||
client.x(function (x) { | ||
assert.equal(x, 20, 'client.x == 20'); | ||
t.equal(x, 20, 'client.x == 20'); | ||
counts.clientX ++; | ||
@@ -30,3 +30,3 @@ f(n * x); | ||
remote.timesX(3, function (res) { | ||
assert.equal(res, 60, 'result of 20 * 3 == 60'); | ||
t.equal(res, 60, 'result of 20 * 3 == 60'); | ||
conn.end(); | ||
@@ -39,5 +39,6 @@ server.close(); | ||
server.once('close', function () { | ||
assert.equal(counts.timesX, 1, 'timesX called once'); | ||
assert.equal(counts.clientX, 1, 'clientX called once'); | ||
t.equal(counts.timesX, 1, 'timesX called once'); | ||
t.equal(counts.clientX, 1, 'clientX called once'); | ||
t.end(); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.broadcast = function () { | ||
test('broadcast', function (t) { | ||
t.plan(3); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -33,3 +33,3 @@ | ||
remote.message('hello!'); | ||
}, 250); | ||
}, 25); | ||
}); | ||
@@ -43,3 +43,3 @@ | ||
remote.message('hey'); | ||
}, 500); | ||
}, 50); | ||
}); | ||
@@ -53,3 +53,3 @@ | ||
remote.message('wowsy'); | ||
}, 750); | ||
}, 75); | ||
}); | ||
@@ -61,18 +61,11 @@ }); | ||
server.close(); | ||
assert.equal( | ||
util.inspect(recv[0]), | ||
"[ '#0 says: hello!', '#1 says: hey', '#2 says: wowsy' ]", | ||
t.deepEqual( | ||
recv[0], | ||
[ '#0 says: hello!', '#1 says: hey', '#2 says: wowsy' ], | ||
"#0 didn't get the right messages" | ||
); | ||
assert.equal( | ||
util.inspect(recv[0]), | ||
util.inspect(recv[1]), | ||
"#1 didn't get the messages" | ||
); | ||
assert.equal( | ||
util.inspect(recv[0]), | ||
util.inspect(recv[2]), | ||
"#2 didn't get the messages" | ||
); | ||
}, 1500); | ||
}; | ||
t.deepEqual(recv[0], recv[1], "#1 didn't get the messages"); | ||
t.deepEqual(recv[0], recv[2], "#2 didn't get the messages"); | ||
t.end(); | ||
}, 150); | ||
}); |
@@ -1,2 +0,2 @@ | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
var dnode = require('../'); | ||
@@ -6,3 +6,4 @@ var http = require('http'); | ||
exports.checkCookieHTTP = function () { | ||
test('checkCookieHTTP', function (t) { | ||
t.plan(3); | ||
var port = Math.floor(10000 + (Math.random() * Math.pow(2,16) - 10000)); | ||
@@ -19,3 +20,3 @@ | ||
}); | ||
var server = dnode().listen(web, { io : { log : null } }); | ||
var server = dnode().listen(web); | ||
@@ -29,5 +30,5 @@ web.listen(port, function () { | ||
http.get(req, function (res) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(res.headers['content-type'], 'text/javascript'); | ||
assert.deepEqual(res.headers['set-cookie'], ['foo=bar']); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-type'], 'text/javascript'); | ||
t.deepEqual(res.headers['set-cookie'], [ 'foo=bar' ]); | ||
@@ -38,5 +39,6 @@ web.close(); | ||
}); | ||
}; | ||
}); | ||
exports.checkCookieExpress = function () { | ||
test('checkCookieExpress', function (t) { | ||
t.plan(3); | ||
var port = Math.floor(10000 + (Math.random() * Math.pow(2,16) - 10000)); | ||
@@ -56,3 +58,3 @@ | ||
var server = dnode().listen(app, { io : { log : null } }); | ||
var server = dnode().listen(app); | ||
@@ -66,10 +68,11 @@ app.listen(port, function () { | ||
http.get(req, function (res) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(res.headers['set-cookie'], 'foo=bar'); | ||
assert.equal(res.headers['content-type'], 'text/javascript'); | ||
t.equal(res.statusCode, 200); | ||
t.deepEqual(res.headers['set-cookie'], [ 'foo=bar' ]); | ||
t.equal(res.headers['content-type'], 'text/javascript'); | ||
app.close(); | ||
server.end(); | ||
t.end(); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports['circular refs'] = function () { | ||
test('circular refs', function (t) { | ||
t.plan(7); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -10,5 +10,5 @@ | ||
sendObj : function (ref, f) { | ||
assert.equal(ref.a, 1); | ||
assert.equal(ref.b, 2); | ||
assert.eql(ref.c, ref); | ||
t.equal(ref.a, 1); | ||
t.equal(ref.b, 2); | ||
t.deepEqual(ref.c, ref); | ||
@@ -27,11 +27,12 @@ ref.d = ref.c; | ||
remote.sendObj(obj, function (ref) { | ||
assert.equal(ref.a, 1); | ||
assert.equal(ref.b, 2); | ||
assert.eql(ref.c, ref); | ||
assert.eql(ref.d, ref); | ||
t.equal(ref.a, 1); | ||
t.equal(ref.b, 2); | ||
t.deepEqual(ref.c, ref); | ||
t.deepEqual(ref.d, ref); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.double = function () { | ||
test('double', function (t) { | ||
t.plan(4); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -23,4 +24,4 @@ | ||
function (x,y) { | ||
assert.equal(x, 20, 'double, not equal'); | ||
assert.equal(y, 5, 'double, not equal'); | ||
t.equal(x, 20, 'double, not equal'); | ||
t.equal(y, 5, 'double, not equal'); | ||
} | ||
@@ -32,9 +33,10 @@ ); | ||
remote.z(plusTen, plusTen, function (x,y) { | ||
assert.equal(x, 20, 'double, equal'); | ||
assert.equal(y, 20, 'double, equal'); | ||
t.equal(x, 20, 'double, equal'); | ||
t.equal(y, 20, 'double, equal'); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
107
test/emit.js
@@ -0,61 +1,68 @@ | ||
var test = require('tap').test; | ||
var EventEmitter = require('events').EventEmitter; | ||
var dnode = require('../'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var assert = require('assert'); | ||
exports['event emitter test'] = function () { | ||
var emitted = false; | ||
var ev = new EventEmitter; | ||
ev.emit = ev.emit.bind(ev); | ||
test('emit events', function (t) { | ||
t.plan(2); | ||
var port = Math.floor(Math.random() * ((1<<16)-1e4)) + 1e4; | ||
ev.on('test1', function (a, b, c) { | ||
assert.equal(a, 1); | ||
assert.equal(b, 2); | ||
assert.eql(c, [3,4]); | ||
emitted = true; | ||
}); | ||
var subs = []; | ||
function publish (name) { | ||
var args = [].slice.call(arguments, 1); | ||
subs.forEach(function (sub) { | ||
sub.emit(name, args); | ||
}); | ||
} | ||
Server.prototype = new EventEmitter; | ||
function Server (client, conn) { | ||
assert.ok(conn.id); | ||
var self = this; | ||
self.on = self.on.bind(self); | ||
self.removeListener = self.removeListener.bind(self); | ||
self.emit = self.emit.bind(self); | ||
self.pass = function (name, em) { | ||
self.on(name, function () { | ||
var args = [].slice.apply(arguments); | ||
args.unshift(name); | ||
em.emit.apply(em, args); | ||
var server = dnode(function (remote, conn) { | ||
this.subscribe = function (emit) { | ||
subs.push({ emit : emit, id : conn.id }); | ||
conn.on('end', function () { | ||
for (var i = 0; i < subs.length; i++) { | ||
if (subs.id === conn.id) { | ||
subs.splice(i, 1); | ||
break; | ||
} | ||
} | ||
}); | ||
}; | ||
setTimeout(function () { | ||
self.emit('test1', 1, 2, [3,4]); | ||
self.emit('test2', 1337); | ||
}, 250); | ||
setTimeout(function () { | ||
assert.ok(emitted, 'test1 event not emitted'); | ||
}, 500); | ||
} | ||
}).listen(port); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var server = dnode(Server).listen(port); | ||
server.on('ready', function () { | ||
dnode.connect(port, function (remote, conn) { | ||
remote.pass('test1', ev); | ||
var test2_calls = 0; | ||
remote.on('test2', function f () { | ||
test2_calls ++; | ||
assert.ok(test2_calls == 1, 'test2 emitter not removed') | ||
remote.removeListener('test2', f); | ||
remote.emit('test2'); | ||
conn.end(); | ||
server.close(); | ||
setTimeout(function () { | ||
var iv = setInterval(function () { | ||
publish('data', Math.floor(Math.random() * 100)); | ||
}, 20); | ||
server.on('close', function () { | ||
clearInterval(iv); | ||
}); | ||
}, 20); | ||
var xs = []; | ||
var x = dnode.connect(port, function (remote) { | ||
var em = new EventEmitter; | ||
em.on('data', function (n) { xs.push(n) }); | ||
remote.subscribe(em.emit.bind(em)); | ||
}); | ||
var ys = []; | ||
var y = dnode.connect(port, function (remote) { | ||
var em = new EventEmitter; | ||
em.on('data', function (n) { ys.push(n) }); | ||
remote.subscribe(em.emit.bind(em)) | ||
}); | ||
setTimeout(function () { | ||
t.ok(xs.length > 5); | ||
t.deepEqual(xs, ys); | ||
x.end(); | ||
y.end(); | ||
server.close(); | ||
t.end(); | ||
}, 200); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var sys = require('sys'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.errors = function () { | ||
test('errors', function (t) { | ||
t.plan(4); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -28,3 +29,3 @@ var errors = { server : [], client : [] }; | ||
var ts = setTimeout(function () { | ||
assert.fail('server never ended'); | ||
t.fail('server never ended'); | ||
}, 5000); | ||
@@ -34,3 +35,3 @@ | ||
clearTimeout(ts); | ||
assert.eql(errors.server[0], 'string throw'); | ||
t.deepEqual(errors.server[0], 'string throw'); | ||
@@ -40,5 +41,6 @@ try { undefined.name } | ||
process.nextTick(function () { | ||
assert.eql(refErr.message, errors.server[1].message); | ||
assert.eql(refErr.type, errors.server[1].type); | ||
assert.equal(errors.server.length, 2); | ||
t.equal(refErr.message, errors.server[1].message); | ||
t.equal(refErr.type, errors.server[1].type); | ||
t.equal(errors.server.length, 2); | ||
t.end(); | ||
}); | ||
@@ -55,3 +57,3 @@ } | ||
conn.on('end', function () { | ||
assert.eql(errors.client, [ 'Local error' ]); | ||
t.deepEqual(errors.client, [ 'Local error' ]); | ||
}); | ||
@@ -74,5 +76,7 @@ | ||
}); | ||
}; | ||
}); | ||
exports.refused = function () { | ||
test('refused', function (t) { | ||
t.plan(2); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -83,11 +87,7 @@ var client = dnode.connect(port, function (remote, conn) { | ||
var to = setTimeout(function () { | ||
assert.fail('never caught error'); | ||
}, 5000); | ||
client.on('error', function (err) { | ||
clearTimeout(to); | ||
assert.equal(err.code, 'ECONNREFUSED'); | ||
assert.equal(err.syscall, 'connect'); | ||
t.equal(err.code, 'ECONNREFUSED'); | ||
t.equal(err.syscall, 'connect'); | ||
t.end(); | ||
}); | ||
} | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.middleware = function () { | ||
test('middleware', function (t) { | ||
t.plan(5); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
var tf = setTimeout(function () { | ||
assert.fail('never finished'); | ||
t.fail('never finished'); | ||
}, 1000); | ||
var tr = setTimeout(function () { | ||
assert.fail('never ready'); | ||
t.fail('never ready'); | ||
}, 1000); | ||
var tc = setTimeout(function () { | ||
assert.fail('connection not ready'); | ||
t.fail('connection not ready'); | ||
}, 1000); | ||
var server = dnode(function (client, conn) { | ||
assert.ok(!conn.zing); | ||
assert.ok(!client.moo); | ||
t.ok(!conn.zing); | ||
t.ok(!client.moo); | ||
conn.on('ready', (function () { | ||
clearTimeout(tr); | ||
assert.ok(conn.zing); | ||
assert.ok(this.moo); | ||
t.ok(conn.zing); | ||
t.ok(this.moo); | ||
}).bind(this)); | ||
@@ -45,7 +47,8 @@ | ||
clearTimeout(tf); | ||
assert.ok(remote.baz); | ||
t.ok(remote.baz); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports['nested'] = function () { | ||
test('nested', function (t) { | ||
t.plan(4); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -26,7 +27,8 @@ | ||
remote1.timesTen(x, function (res) { | ||
assert.equal(res, 5000, 'emitted value times ten'); | ||
t.equal(res, 5000, 'emitted value times ten'); | ||
remote2.timesTwenty(res, function (res2) { | ||
assert.equal(res2, 100000, 'result times twenty'); | ||
t.equal(res2, 100000, 'result times twenty'); | ||
conn1.end(); conn2.end(); | ||
server1.close(); server2.close(); | ||
t.end(); | ||
}); | ||
@@ -36,5 +38,5 @@ }); | ||
remote2.timesTwenty(5, function (n) { | ||
assert.equal(n, 100); | ||
t.equal(n, 100); | ||
remote1.timesTen(0.1, function (n) { | ||
assert.equal(n, 1); | ||
t.equal(n, 1); | ||
}); | ||
@@ -50,2 +52,2 @@ }); | ||
}, 200); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.null = function () { | ||
test('null', function (t) { | ||
t.plan(7); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -10,3 +11,3 @@ | ||
timesTen : function (n, reply) { | ||
assert.equal(n, 50); | ||
t.equal(n, 50); | ||
reply(n * 10); | ||
@@ -16,3 +17,3 @@ }, | ||
sTimesTen : function (n, cb) { | ||
assert.equal(n, 5); | ||
t.equal(n, 5); | ||
cb(n * 10, null); | ||
@@ -24,14 +25,15 @@ }, | ||
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(); | ||
}); | ||
@@ -41,2 +43,2 @@ }); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports['object ref tests'] = function () { | ||
test('object ref tests', function (t) { | ||
t.plan(8); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -16,14 +17,15 @@ | ||
remote.getObject(function (rObj) { | ||
assert.equal(rObj.a, 1); | ||
assert.equal(rObj.b, 2); | ||
assert.equal(typeof rObj.f, 'function'); | ||
t.equal(rObj.a, 1); | ||
t.equal(rObj.b, 2); | ||
t.equal(typeof rObj.f, 'function'); | ||
rObj.a += 100; rObj.b += 100; | ||
assert.equal(obj.a, 1); | ||
assert.equal(obj.b, 2); | ||
assert.notEqual(obj.f, rObj.g); | ||
assert.equal(typeof obj.f, 'function'); | ||
t.equal(obj.a, 1); | ||
t.equal(obj.b, 2); | ||
t.notEqual(obj.f, rObj.g); | ||
t.equal(typeof obj.f, 'function'); | ||
rObj.f(13, function (res) { | ||
assert.equal(res, 260); | ||
t.equal(res, 260); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
@@ -33,2 +35,2 @@ }); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.recon = function () { | ||
test('recon', function (t) { | ||
t.plan(4); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -17,4 +18,2 @@ | ||
var alive = true; | ||
dnode(function (remote, conn) { | ||
@@ -37,11 +36,11 @@ ccounts.connect ++; | ||
setTimeout(function () { | ||
assert.ok(scounts.connect >= 2); | ||
assert.ok(scounts.ready >= 2); | ||
t.ok(scounts.connect >= 2); | ||
t.ok(scounts.ready >= 2); | ||
assert.eql(ccounts.connect, scounts.connect); | ||
assert.eql(ccounts.ready, scounts.ready); | ||
t.equal(ccounts.connect, scounts.connect); | ||
t.equal(ccounts.ready, scounts.ready); | ||
server.close(); | ||
alive = false; | ||
t.end(); | ||
}, 1000); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.refs = function () { | ||
test('refs', function (t) { | ||
t.plan(2); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -16,6 +17,7 @@ | ||
server.close(); | ||
assert.equal(remote.a, 1); | ||
assert.equal(remote.b, 2); | ||
t.equal(remote.a, 1); | ||
t.equal(remote.b, 2); | ||
t.end(); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../') | ||
var assert = require('assert'); | ||
var util = require('util'); | ||
var test = require('tap').test; | ||
exports.simple = function () { | ||
test('simple', function (t) { | ||
t.plan(6); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -10,10 +10,10 @@ | ||
timesTen : function (n,reply) { | ||
assert.equal(n.number, 5); | ||
t.equal(n.number, 5); | ||
reply(n.number * 10); | ||
}, | ||
print : function (n,reply) { | ||
assert.strictEqual(n[0],1); | ||
assert.strictEqual(n[1],2); | ||
assert.strictEqual(n[2],3); | ||
assert.strictEqual(n[3],n); | ||
t.strictEqual(n[0],1); | ||
t.strictEqual(n[1],2); | ||
t.strictEqual(n[2],3); | ||
t.strictEqual(n[3],n); | ||
reply(n); | ||
@@ -25,3 +25,3 @@ }, | ||
dnode.connect(port, function (remote, conn) { | ||
assert.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
t.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
var args = [1,2,3] | ||
@@ -31,13 +31,10 @@ args.push(args) | ||
remote.print(args, function (m) { | ||
assert.eql( | ||
util.inspect(m), | ||
util.inspect(args) | ||
); | ||
t.deepEqual(m, args); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
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); | ||
@@ -9,3 +10,3 @@ | ||
timesTen : function (n,reply) { | ||
assert.equal(n, 50); | ||
t.equal(n, 50); | ||
reply(n * 10); | ||
@@ -15,3 +16,3 @@ }, | ||
sTimesTen : function (n, cb) { | ||
assert.equal(n, 5); | ||
t.equal(n, 5); | ||
cb(n * 10); | ||
@@ -23,14 +24,15 @@ }, | ||
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(); | ||
}); | ||
@@ -40,2 +42,2 @@ }); | ||
}); | ||
}; | ||
}); |
var dnode = require('../') | ||
var util = require('util'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.simple = function () { | ||
test('simple', function (t) { | ||
t.plan(3); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -10,3 +10,3 @@ | ||
timesTen : function (n,reply) { | ||
assert.equal(n.number, 5); | ||
t.equal(n.number, 5); | ||
reply(n.number * 10); | ||
@@ -21,3 +21,3 @@ }, | ||
dnode.connect(port, function (remote, conn) { | ||
assert.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
t.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
var args = { | ||
@@ -29,8 +29,9 @@ number : 5, | ||
remote.timesTen(args, function (m) { | ||
assert.equal(m, 50, '5 * 10 == 50'); | ||
t.equal(m, 50, '5 * 10 == 50'); | ||
conn.end(); | ||
server.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
@@ -1,6 +0,7 @@ | ||
var assert = require('assert'); | ||
var dnode = require('../'); | ||
var net = require('net'); | ||
var test = require('tap').test; | ||
exports.stream = function () { | ||
test('stream', function (t) { | ||
t.plan(1); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -15,6 +16,2 @@ | ||
var to = setTimeout(function () { | ||
assert.fail(); | ||
}, 5000); | ||
var times = 0; | ||
@@ -25,10 +22,10 @@ netServer.listen(port, function () { | ||
remote.meow(function (cats) { | ||
clearTimeout(to); | ||
assert.equal(cats, 'cats'); | ||
t.equal(cats, 'cats'); | ||
netClient.end(); | ||
netServer.close(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
@@ -9,3 +9,3 @@ // (A) dnode.listen(tls.createServer(options),cb) | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
var dnode = require('../'); | ||
@@ -34,11 +34,13 @@ var tls = require('tls'); | ||
exports.tls = function () { | ||
var AC = setTimeout(function () { assert.fail(); }, 500); | ||
var AD = setTimeout(function () { assert.fail(); }, 500); | ||
var BC = setTimeout(function () { assert.fail(); }, 500); | ||
var BD = setTimeout(function () { assert.fail(); }, 500); | ||
var CA = setTimeout(function () { assert.fail(); }, 500); | ||
var CB = setTimeout(function () { assert.fail(); }, 500); | ||
var DA = setTimeout(function () { assert.fail(); }, 500); | ||
var DB = setTimeout(function () { assert.fail(); }, 500); | ||
test('tls', function (t) { | ||
t.plan(4); | ||
var AC = setTimeout(function () { t.fail(); }, 500); | ||
var AD = setTimeout(function () { t.fail(); }, 500); | ||
var BC = setTimeout(function () { t.fail(); }, 500); | ||
var BD = setTimeout(function () { t.fail(); }, 500); | ||
var CA = setTimeout(function () { t.fail(); }, 500); | ||
var CB = setTimeout(function () { t.fail(); }, 500); | ||
var DA = setTimeout(function () { t.fail(); }, 500); | ||
var DB = setTimeout(function () { t.fail(); }, 500); | ||
@@ -57,4 +59,3 @@ var tlsServer = tls.createServer(optionsA); | ||
remote.name(function (data) { | ||
assert.equal(data,'A'); | ||
clearTimeout(AC); | ||
t.equal(data,'A'); | ||
con.end(); | ||
@@ -66,4 +67,3 @@ }); | ||
remote.name(function (data) { | ||
assert.equal(data,'A'); | ||
clearTimeout(AD); | ||
t.equal(data,'A'); | ||
con.end(); | ||
@@ -83,4 +83,3 @@ }); | ||
remote.name(function (data) { | ||
clearTimeout(BC); | ||
assert.equal(data,'B'); | ||
t.equal(data,'B'); | ||
con.end(); | ||
@@ -92,4 +91,3 @@ }); | ||
remote.name(function (data) { | ||
assert.equal(data,'B'); | ||
clearTimeout(BD); | ||
t.equal(data,'B'); | ||
con.end(); | ||
@@ -101,7 +99,6 @@ }); | ||
setTimeout(function () { | ||
tlsServer.close(); | ||
B.close(); | ||
tlsServer.close(); | ||
B.close(); | ||
t.end(); | ||
}, 500); | ||
} | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.simple = function () { | ||
test('unicode', function (t) { | ||
t.plan(2); | ||
var port = Math.floor(Math.random() * 40000 + 10000); | ||
@@ -15,13 +16,12 @@ | ||
dnode.connect(port, function (remote, conn) { | ||
assert.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
t.equal(conn.stream.remoteAddress, '127.0.0.1'); | ||
remote.unicodes(function (str) { | ||
assert.equal(str, '☔☔☔☁☼☁❄', 'remote unicodes == ☔☔☔☁☼☁❄'); | ||
}); | ||
setTimeout(function () { | ||
t.equal(str, '☔☔☔☁☼☁❄', 'remote unicodes == ☔☔☔☁☼☁❄'); | ||
conn.end(); | ||
server.close(); | ||
}, 50); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
var dnode = require('../'); | ||
var assert = require('assert'); | ||
var test = require('tap').test; | ||
exports.unix = function () { | ||
test('unix', function (t) { | ||
t.plan(1); | ||
var sfile = '/tmp/unix_socket_' + Math.floor( | ||
@@ -9,6 +11,2 @@ Math.random() * Math.pow(2, 32) | ||
var to = setTimeout(function () { | ||
assert.fail('never connected'); | ||
}, 5000); | ||
var server = dnode({ f : function (cb) { cb(1337) } }).listen(sfile); | ||
@@ -19,9 +17,9 @@ | ||
remote.f(function (x) { | ||
clearTimeout(to); | ||
assert.equal(x, 1337); | ||
t.equal(x, 1337); | ||
server.close(); | ||
conn.end(); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
471259
176
11477
314
5
54
16
+ Addedjsonify@0.0.x
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddnode-protocol@0.1.5(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.2(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtraverse@0.6.9(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedtypedarray.prototype.slice@1.0.3(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
- Removeddnode-protocol@0.0.12(transitive)
- Removedsocket.io@0.6.18(transitive)
Updateddnode-protocol@0.1.x
Updatedsocket.io@https://github.com/substack/socket.io-client/tarball/master