forked from foreversd/forever
/
forever-test.js
87 lines (82 loc) · 2.43 KB
/
forever-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
76
77
78
79
80
81
82
83
84
85
86
87
/*
* forever-test.js: Tests for forever module
*
* (C) 2010 and Charlie Robbins
* MIT LICENCE
*
*/
require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var sys = require('sys'),
assert = require('assert'),
path = require('path'),
vows = require('vows'),
forever = require('forever');
vows.describe('forever').addBatch({
"When using forever": {
topic: function () {
forever.load({}, this.callback);
},
"and instance of Forever passed valid options": {
topic: function () {
var child = new (forever.Forever)('any-file.js', {
max: 10,
silent: true,
options: []
});
// Emit a useless callback since we can't return
// an instance of an events.EventEmitter
child.on('test', this.callback);
child.emit('test', null, child);
},
"should have correct properties set": function (err, child) {
assert.isArray(child.options);
assert.equal(child.max, 10);
assert.isTrue(child.silent);
assert.isFunction(child.start);
assert.isFunction(child.save);
assert.isFunction(child.stop);
}
}
},
"running error-on-timer sample three times": {
topic: function () {
var child = new (forever.Forever)(path.join(__dirname, '..', 'samples', 'error-on-timer.js'), {
max: 3,
silent: true,
outFile: 'test/stdout.log',
errFile: 'test/stderr.log',
options: []
});
child.on('exit', this.callback);
child.start();
},
"should emit 'exit' when completed": function (err, child) {
assert.equal(child.times, 3);
}
},
"non-node usage with a perl one-liner": {
topic: function () {
var child = forever.start([ 'perl', '-le', 'print "moo"' ], {
max: 1,
silent: true,
});
child.on('stdout', this.callback.bind({}, null));
},
"should get back moo": function (err, buf) {
assert.equal(buf.toString(), 'moo\n');
}
},
"attempting to start a script that doesn't exist": {
topic: function () {
var child = forever.start('invalid-path.js', {
max: 1,
silent: true
});
child.on('error', this.callback.bind({}, null));
},
"should throw an error about the invalid file": function (err) {
assert.isNotNull(err);
assert.isTrue(err.message.indexOf('does not exist') !== -1);
}
}
}).export(module);