retarget.js 646 B

12345678910111213141516171819202122232425
  1. var test = require('tap').test;
  2. var spawn = require('child_process').spawn;
  3. var path = require('path');
  4. var vm = require('vm');
  5. test('retarget with -r', function (t) {
  6. t.plan(2);
  7. var ps = spawn(process.execPath, [
  8. path.resolve(__dirname, '../bin/cmd.js'),
  9. '-r', 'beep'
  10. ], { cwd: __dirname });
  11. var src = '';
  12. ps.stdout.on('data', function (buf) { src += buf });
  13. ps.stderr.pipe(process.stderr);
  14. ps.on('exit', function (code) {
  15. t.equal(code, 0);
  16. var c = {};
  17. vm.runInNewContext(src, c);
  18. t.equal(c.require('beep'), 'boop');
  19. });
  20. ps.stdin.end();
  21. });