forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
executable file
·53 lines (43 loc) · 1.23 KB
/
Copy pathmiddleware.js
File metadata and controls
executable file
·53 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var dnode = require('../');
var test = require('tap').test;
test('middleware', function (t) {
t.plan(5);
var port = Math.floor(Math.random() * 40000 + 10000);
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) {
t.ok(!conn.zing);
t.ok(!client.moo);
conn.on('ready', (function () {
clearTimeout(tr);
t.ok(conn.zing);
t.ok(this.moo);
}).bind(this));
this.baz = 42;
}).listen(port);
server.use(function (client, conn) {
conn.zing = true;
});
server.use(function (client, conn) {
this.moo = true;
conn.on('ready', function () {
clearTimeout(tc);
});
});
server.on('ready', function () {
dnode.connect(port, function (remote, conn) {
clearTimeout(tf);
t.ok(remote.baz);
conn.end();
server.close();
t.end();
});
});
});