Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50661 views
1
/*
2
* watch-test.js: Tests for restarting forever processes when a file changes.
3
*
4
* (C) 2010 Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
path = require('path'),
11
fs = require('fs'),
12
vows = require('vows'),
13
fmonitor = require('../../lib');
14
15
vows.describe('forever-monitor/plugins/watch').addBatch({
16
'When using forever with watch enabled': {
17
'forever should': {
18
topic: fmonitor.start('daemon.js', {
19
silent: true,
20
options: ['-p', '8090'],
21
watch: true,
22
sourceDir: path.join(__dirname, '..', 'fixtures', 'watch')
23
}),
24
'have correct options set': function (child) {
25
assert.isTrue(child.watchIgnoreDotFiles);
26
assert.equal(fs.realpathSync(path.join(__dirname, '..', 'fixtures', 'watch')),
27
fs.realpathSync(child.watchDirectory));
28
},
29
'when file changes': {
30
topic: function (child) {
31
child.once('restart', this.callback);
32
fs.writeFileSync(path.join(__dirname, '..', 'fixtures', 'watch', 'file'),
33
'// hello, I know nodejitsu.');
34
},
35
'restart the script': function (child, _) {
36
fs.writeFileSync(path.join(__dirname, '..', 'fixtures', 'watch', 'file'),
37
'/* hello, I know nodejitsu. */');
38
}
39
},
40
'when file is added': {
41
topic: function (child) {
42
child.once('restart', this.callback);
43
fs.writeFileSync(path.join(__dirname, '..', 'fixtures', 'watch', 'newFile'), '');
44
},
45
'restart the script': function (child, _) {
46
fs.unlinkSync(path.join(__dirname, '..', 'fixtures', 'watch', 'newFile'));
47
}
48
},
49
'when file is removed': {
50
topic: function (child) {
51
child.once('restart', this.callback);
52
try { fs.unlinkSync(path.join(__dirname, '..', 'fixtures', 'watch', 'removeMe')) }
53
catch (ex) { }
54
},
55
'restart the script': function (child, _) {
56
fs.writeFileSync(path.join(__dirname, '..', 'fixtures', 'watch', 'removeMe'), '');
57
}
58
},
59
'read .foreverignore file': {
60
'and store ignore patterns': function (child) {
61
assert.deepEqual(
62
child.watchIgnorePatterns,
63
fs.readFileSync(
64
path.join(__dirname, '..', 'fixtures', 'watch', '.foreverignore'),
65
'utf8'
66
).split("\n")
67
);
68
}
69
}
70
}
71
}
72
}).export(module);
73