index.js
1.08 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
54
55
56
57
58
59
60
61
62
63
64
//var a = require('assertions')
var es = require('event-stream')
var MuxDemux = require('../')
module.exports = function (wrapper) {
require('tape')('simple test', function (a) {
var A = MuxDemux({wrapper: wrapper})
var B = MuxDemux({wrapper: wrapper})
var connected, closed, ended, _hi
B.on('connection', function (hi) {
_hi = hi
console.log('CONNECTION')
a.equal(hi.meta.name, 'hello')
connected = true
hi.once('data', function (data) {
a.equal(data, 'whatever')
})
})
A.pipe(B).pipe(A)
var hi = A.createStream({name: 'hello'}, {allowHalfOpen: true})
hi.write('whatever')
//A.resume()
//B.resume()
process.nextTick(function () {
a.ok(connected)
hi.on('close', function eee () {
closed = true
})
hi.end()
a.equal(hi.writable, false)
a.equal(_hi.readable, false)
_hi.end()
a.equal(_hi.writable, false)
a.equal(hi.readable, false)
hi.on('close', function () { console.log('HI CLOSE') })
_hi.on('close', function () { console.log('_HI CLOSE') })
A.end()
a.ok(closed)
a.ok(!ended)
a.end()
})
})
}
if(!module.parent)
module.exports()