Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
/*
2
* env-spawn-test.js: Tests for supporting environment variables in the forever module
3
*
4
* (C) 2010 Nodejitsu Inc.
5
* MIT LICENCE
6
*
7
*/
8
9
var assert = require('assert'),
10
path = require('path'),
11
vows = require('vows'),
12
fmonitor = require('../../lib');
13
14
vows.describe('forever-monitor/monitor/spawn-options').addBatch({
15
"When using forever-monitor": {
16
"an instance of Monitor with valid options": {
17
"passing environment variables to env-vars.js": {
18
topic: function () {
19
var that = this, child;
20
21
this.env = {
22
FOO: 'foo',
23
BAR: 'bar'
24
};
25
26
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'env-vars.js'), {
27
max: 1,
28
silent: true,
29
minUptime: 0,
30
env: this.env
31
});
32
33
child.on('stdout', function (data) {
34
that.stdout = data.toString();
35
});
36
37
child.on('exit', this.callback.bind({}, null));
38
child.start();
39
},
40
"should pass the environment variables to the child": function (err, child) {
41
assert.equal(child.times, 1);
42
assert.equal(this.stdout, JSON.stringify(this.env));
43
}
44
},
45
"passing a custom cwd to custom-cwd.js": {
46
topic: function () {
47
var that = this, child;
48
49
this.cwd = path.join(__dirname, '..');
50
51
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'custom-cwd.js'), {
52
max: 1,
53
silent: true,
54
minUptime: 0,
55
cwd: this.cwd
56
});
57
58
child.on('stdout', function (data) {
59
that.stdout = data.toString();
60
});
61
62
child.on('exit', this.callback.bind({}, null));
63
child.start();
64
},
65
"should setup the child to run in the target directory": function (err, child) {
66
assert.equal(child.times, 1);
67
assert.equal(this.stdout, this.cwd);
68
}
69
},
70
"setting `hideEnv` when spawning all-env-vars.js": {
71
topic: function () {
72
var that = this, child;
73
74
this.hideEnv = [
75
'USER',
76
'OLDPWD'
77
];
78
79
child = new (fmonitor.Monitor)(path.join(__dirname, '..', '..', 'examples', 'all-env-vars.js'), {
80
max: 1,
81
silent: true,
82
minUptime: 0,
83
hideEnv: this.hideEnv
84
});
85
86
child.on('stdout', function (data) {
87
that.env = Object.keys(JSON.parse(data.toString()));
88
});
89
90
child.on('exit', this.callback.bind(this, null));
91
child.start();
92
},
93
"should hide the environment variables passed to the child": function (err, child) {
94
var that = this;
95
96
assert.equal(child.times, 1);
97
this.hideEnv.forEach(function (key) {
98
assert.isTrue(that.env.indexOf(key) === -1);
99
});
100
}
101
},
102
}
103
}
104
}).export(module);
105
106