08-27-周三_17-09-29
This commit is contained in:
51
node_modules/dnode/test/middleware.js
generated
vendored
Normal file
51
node_modules/dnode/test/middleware.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
var dnode = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
test('middleware', function (t) {
|
||||
t.plan(5);
|
||||
|
||||
var tf = setTimeout(function () {
|
||||
t.fail('never finished');
|
||||
}, 1000);
|
||||
|
||||
var tr = setTimeout(function () {
|
||||
t.fail('never ready');
|
||||
}, 1000);
|
||||
|
||||
var tc = setTimeout(function () {
|
||||
t.fail('connection not ready');
|
||||
}, 1000);
|
||||
|
||||
var server = dnode(function (client, conn) {
|
||||
var self = this;
|
||||
t.ok(!conn.zing);
|
||||
t.ok(!client.moo);
|
||||
|
||||
conn.on('remote', function () {
|
||||
clearTimeout(tr);
|
||||
t.ok(conn.zing);
|
||||
t.ok(self.moo);
|
||||
});
|
||||
|
||||
this.baz = 42;
|
||||
});
|
||||
|
||||
server.on('local', function (client, conn) {
|
||||
conn.zing = true;
|
||||
});
|
||||
|
||||
server.on('local', function (client, conn) {
|
||||
client.moo = true;
|
||||
conn.on('remote', function () {
|
||||
clearTimeout(tc);
|
||||
});
|
||||
});
|
||||
|
||||
var client = dnode();
|
||||
client.on('remote', function (remote, conn) {
|
||||
clearTimeout(tf);
|
||||
t.ok(remote.baz);
|
||||
});
|
||||
|
||||
server.pipe(client).pipe(server);
|
||||
});
|
Reference in New Issue
Block a user