env-spawn-test.js
3.42 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* env-spawn-test.js: Tests for supporting environment variables in the forever module
*
* (C) 2010 Charlie Robbins & the Contributors
* MIT LICENCE
*
*/
var assert = require('assert'),
path = require('path'),
vows = require('vows'),
fmonitor = require('../../lib');
vows.describe('forever-monitor/monitor/spawn-options').addBatch({
"When using forever-monitor": {
"an instance of Monitor with valid options": {
"passing environment variables to env-vars.js": {
topic: function () {
var that = this, child;
this.env = {
FOO: 'foo',
BAR: 'bar'
};
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'env-vars.js'), {
max: 1,
silent: true,
minUptime: 0,
env: this.env
});
child.on('stdout', function (data) {
that.stdout = data.toString();
});
child.on('exit', this.callback.bind({}, null));
child.start();
},
"should pass the environment variables to the child": function (err, child) {
assert.equal(child.times, 1);
assert.equal(this.stdout, JSON.stringify(this.env));
}
},
"passing a custom cwd to custom-cwd.js": {
topic: function () {
var that = this, child;
this.cwd = path.join(__dirname, '..');
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'custom-cwd.js'), {
max: 1,
silent: true,
minUptime: 0,
cwd: this.cwd
});
child.on('stdout', function (data) {
that.stdout = data.toString();
});
child.on('exit', this.callback.bind({}, null));
child.start();
},
"should setup the child to run in the target directory": function (err, child) {
assert.equal(child.times, 1);
assert.equal(this.stdout, this.cwd);
}
},
"setting `hideEnv` when spawning all-env-vars.js": {
topic: function () {
var that = this,
all = '',
confirmed,
child;
this.hideEnv = [
'USER',
'OLDPWD'
];
//
// Remark (indexzero): This may be a symptom of a larger bug.
// This test only fails when run under `npm test` (e.g. vows --spec -i).
//
function tryCallback() {
if (confirmed) {
return that.callback(null, child);
}
confirmed = true;
}
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'all-env-vars.js'), {
max: 1,
silent: true,
minUptime: 0,
hideEnv: this.hideEnv
});
child.on('stdout', function (data) {
all += data;
try { that.env = Object.keys(JSON.parse(all)); }
catch (ex) { }
tryCallback();
});
child.on('exit', tryCallback);
child.start();
},
"should hide the environment variables passed to the child": function (err, child) {
var that = this;
assert.equal(child.times, 1);
this.hideEnv.forEach(function (key) {
assert.isTrue(that.env.indexOf(key) === -1);
});
}
},
}
}
}).export(module);