Skip to content

Commit d891990

Browse files
committed
[test] Add tests for watch
Please note that tests are synchronous because of possible race conditions.
1 parent f636447 commit d891990

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

test/watch-test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* watch-test.js
3+
*
4+
* (C) 2010 and Charlie Robbins
5+
* MIT LICENSE
6+
*
7+
*/
8+
9+
var assert = require('assert'),
10+
path = require('path'),
11+
fs = require('fs'),
12+
vows = require('vows'),
13+
forever = require('../lib/forever');
14+
15+
vows.describe('forever/watch').addBatch({
16+
'When using forever with watch enabled': {
17+
'forever should': {
18+
topic: forever.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+
fs.unlinkSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe'));
53+
},
54+
'restart the script': function (child, _) {
55+
fs.writeFileSync(path.join(__dirname, 'fixtures', 'watch', 'removeMe'), '');
56+
}
57+
},
58+
'read .foreverignore file': {
59+
'and store ignore patterns': function (child) {
60+
assert.deepEqual(
61+
child.watchIgnorePatterns,
62+
fs.readFileSync(
63+
path.join(__dirname, 'fixtures', 'watch', '.foreverignore'),
64+
'utf8'
65+
).split("\n")
66+
);
67+
}
68+
}
69+
}
70+
}
71+
}).export(module);
72+

0 commit comments

Comments
 (0)