/
child-argument-test.js
75 lines (66 loc) · 2.08 KB
/
child-argument-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* child-argument-test.js: Basic child argument rewrite tests
*
* (C) 2011 stolsma
* MIT LICENCE
*
*/
var assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn,
vows = require('vows'),
helper = require('../helper/macros.js'),
carapace = require('../../lib/carapace');
var script = path.join(__dirname, '..', 'fixtures' ,'checkchildargs.js'),
IOPORT = 5060,
testPort = 8000,
checkargs = ['argument', '-a', 'aargument', '--test', 'testargument'];
argv = ['--hook-port', IOPORT, '--hook-name', 'carapace', script];
vows.describe('carapace/simple/child-argument').addBatch({
"When using haibu-carapace": {
"spawning the checkchildargs.js script via the child carapace": {
topic: function () {
var that = this,
child,
result;
result = {
arguments: '',
exitCode: -1
};
child = spawn(carapace.bin, argv.concat(checkargs));
child.stdout.on('data', function (data) {
result.arguments += data;
});
child.on('exit', function (code) {
result.exitCode = code;
//
// Process all events before asserting
//
process.nextTick(function () {
that.callback(null, result, child);
});
});
},
"should exit": {
topic: function (info, child) {
this.callback(null, info, child);
},
"with the correct exit code": function (_, info, child) {
assert.equal(info.exitCode, 0);
},
"and correct client arguments": function (_, info, child) {
var childargs = JSON.parse(info.arguments),
resultScript,
node,
//
// First two are reference to node and the script itself
//
node = childargs.splice(0, 1);
resultScript = childargs.splice(0, 1);
assert.equal(resultScript, script);
assert.deepEqual(childargs, checkargs);
}
}
}
}
}).export(module);