Initial commit
[yaffs-website] / node_modules / stdout-stream / test / index.js
1 var tape = require('tape');
2 var proc = require('child_process');
3 var path = require('path');
4
5 tape('print to stdout', function(t) {
6         proc.exec('"'+process.execPath+'" '+path.join(__dirname,'fixtures','hello-world.js'), function(err, stdout) {
7                 t.ok(!err);
8                 t.same(stdout,'hello\nworld\n');
9                 t.end();
10         });
11 });
12
13 tape('end stdout', function(t) {
14         var ch = proc.exec('"'+process.execPath+'" '+path.join(__dirname,'fixtures','end.js'));
15         var buf = [];
16         var processOnExit = false;
17         var stdoutOnEnd = false;
18
19         ch.stdout.on('data', function(data) {
20                 buf.push(data);
21         });
22         ch.stdout.on('end', function() {
23                 t.same(Buffer.concat(buf).toString(), 'stdout');
24                 t.ok(!processOnExit);
25                 stdoutOnEnd = true;
26         });
27         ch.on('exit', function(code) {
28                 processOnExit = true;
29                 t.ok(stdoutOnEnd);
30                 t.same(code, 0);
31                 t.end();
32         });
33 });