forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd-streams.ts
More file actions
30 lines (27 loc) · 899 Bytes
/
std-streams.ts
File metadata and controls
30 lines (27 loc) · 899 Bytes
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
import assert from '../../harness/wrapped-assert';
export default function() {
var datStr = "hey\nhere's some data.",
count = 0,
cb = function(stream: NodeJS.ReadWriteStream) {
return function(data: Buffer) {
assert(typeof(data) !== 'string');
assert.equal(data.toString(), datStr);
count++;
}
},
streams = [process.stdout, <any> process.stderr, process.stdin];
for (let i = 0; i < streams.length; i++) {
streams[i].on('data', cb(streams[i]));
// Write as string, receive as buffer.
streams[i].write(datStr);
// Write as buffer, receive as buffer.
streams[i].write(new Buffer(datStr));
}
process.on('exit', function() {
for (let i = 0; i < streams.length; i++) {
// Remove all listeners.
streams[i].removeAllListeners('data');
}
assert.equal(count, 6);
});
};