-
Notifications
You must be signed in to change notification settings - Fork 23
/
test.js
executable file
·49 lines (37 loc) · 1.15 KB
/
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
#!/usr/bin/env node
var test = require('tape');
var nativeMessaging = require('./index');
test('Input', function(t) {
var buf =typeof Buffer.alloc === 'function' ? Buffer.alloc(17) : new Buffer(17);
buf.writeUInt32LE(13, 0);
buf.write('{"foo":"bar"}', 4);
var input = new nativeMessaging.Input();
input.once('readable', function() {
var obj = input.read();
t.equal(obj.foo, 'bar');
t.end();
});
input.end(buf);
});
test('Output', function(t) {
var output = new nativeMessaging.Output();
output.once('readable', function() {
var buf = output.read();
t.equal(buf.readUInt32LE(0), 13);
t.equal(buf.slice(4).toString(), '{"foo":"bar"}');
t.end();
});
output.end({ foo: 'bar' });
});
test('Transform', function(t) {
var transform = new nativeMessaging.Transform(function(msg, push, done) {
push({ output: msg.input.toUpperCase() });
done();
});
transform.once('readable', function() {
var obj = transform.read();
t.equal(obj.output, 'data'.toUpperCase());
t.end();
});
transform.end({ input: 'data' });
});