Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80517 views
1
var test = require('tap').test;
2
var spawn = require('child_process').spawn;
3
var path = require('path');
4
var concat = require('concat-stream');
5
var vm = require('vm');
6
7
test('bare', function (t) {
8
t.plan(4);
9
10
var cwd = process.cwd();
11
process.chdir(__dirname);
12
13
var ps = spawn(process.execPath, [
14
path.resolve(__dirname, '../bin/cmd.js'),
15
'-', '--bare'
16
]);
17
ps.stdout.pipe(concat(function (body) {
18
vm.runInNewContext(body, {
19
Buffer: function (s) { return s.toLowerCase() },
20
console: {
21
log: function (msg) { t.equal(msg, 'abc') }
22
}
23
});
24
vm.runInNewContext(body, {
25
Buffer: Buffer,
26
console: {
27
log: function (msg) {
28
t.ok(Buffer.isBuffer(msg));
29
t.equal(msg.toString('utf8'), 'ABC')
30
}
31
}
32
});
33
}));
34
ps.stdin.end('console.log(Buffer("ABC"))');
35
36
ps.on('exit', function (code) {
37
t.equal(code, 0);
38
});
39
});
40
41