UNPKG

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