UNPKG

1.02 kBJavaScriptView Raw
1var test = require('tap').test;
2var spawn = require('child_process').spawn;
3var path = require('path');
4var vm = require('vm');
5
6test('compiling coffee with -c', function (t) {
7 t.plan(4);
8
9 var cwd = process.cwd();
10 process.chdir(__dirname);
11
12 var ps = spawn(process.execPath, [
13 path.resolve(__dirname, '../bin/cmd.js'),
14 '-c', '"' + process.execPath + '" "' + __dirname + '/../node_modules/coffee-script/bin/coffee" -sc',
15 'coffee_bin/main.coffee'
16 ]);
17 var src = '';
18 var err = '';
19 ps.stdout.on('data', function (buf) { src += buf });
20 ps.stderr.on('data', function (buf) { err += buf });
21
22 ps.on('exit', function (code) {
23 t.equal(code, 0);
24 t.equal(err, '');
25
26 var msgs = [ 'hello world!', 'from x!' ];
27 var c = {
28 console: {
29 log: function (msg) {
30 t.equal(msg, msgs.shift());
31 }
32 }
33 };
34 vm.runInNewContext(src, c);
35 });
36});