-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
54 lines (46 loc) · 1023 Bytes
/
test.js
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
var test = require('tap').test
var noface = require('./')
function wrap (t, src) {
var ph = noface(src, { stdio: [0, 1, 2] })
ph.on('error', function () {
t.fail('noface')
})
return ph
}
test('open and close from child', function (t) {
t.plan(1)
var ph = wrap(t, function (channel) {
channel.close()
})
ph.on('close', function () {
t.pass('close from child')
})
})
test('open and close from parent', function (t) {
t.plan(1)
var ph = wrap(t, function (channel) {})
ph.on('open', function () {
process.nextTick(function () {
ph.close()
})
})
ph.on('close', function () {
t.pass('close from parent')
})
})
test('messaging', function (t) {
t.plan(1)
var message = 'Hello world!'
var ph = wrap(t, function (channel) {
channel.onmessage = function (event) {
channel.send(event.data)
}
})
ph.on('open', function () {
ph.send(message)
})
ph.on('message', function (s) {
t.equal(s, message, 'echo test')
ph.close()
})
})