stdin.js 803 B

1234567891011121314151617181920212223242526272829303132333435
  1. var test = require('tap').test;
  2. var spawn = require('child_process').spawn;
  3. var concat = require('concat-stream');
  4. var path = require('path');
  5. var vm = require('vm');
  6. test('stdin', function (t) {
  7. t.plan(2);
  8. var cwd = process.cwd();
  9. process.chdir(__dirname);
  10. var ps = spawn(process.execPath, [
  11. path.resolve(__dirname, '../bin/cmd.js'),
  12. '-'
  13. ]);
  14. ps.stdout.pipe(concat(function (body) {
  15. var c = { console: {
  16. log: function (msg) {
  17. t.equal(msg, 'hello');
  18. }
  19. } };
  20. vm.runInNewContext(body, c);
  21. }));
  22. ps.stderr.pipe(process.stderr);
  23. ps.on('exit', function (code) {
  24. t.equal(code, 0);
  25. });
  26. ps.stdin.write("console.log('hello')");
  27. ps.stdin.end();
  28. });