Permalink
Browse files

[fix test] Update `watch` tests to work with `chokidar`.

  • Loading branch information...
indexzero committed Jul 23, 2015
1 parent 12e35fc commit 6ed022bf2d8ac96d4348c81ffaebb0063b82e001
Showing with 63 additions and 58 deletions.
  1. +2 −1 lib/forever-monitor/plugins/watch.js
  2. +1 −1 test/fixtures/watch/file
  3. +60 −56 test/plugins/watch-test.js
@@ -68,11 +68,12 @@ exports.attach = function () {
return !watchFilter.call(monitor, fileName);
}
};
// Or, ignore: function(fileName) { return !watchFilter(fileName) }
chokidar
.watch(this.watchDirectory, opts)
.on('all', function(f, stat) {
monitor.emit('watch:restart', { file: f, stat: stat });
monitor.restart();
})
});
};
View
@@ -1 +1 @@
/* hello, I know nodejitsu. */
/* hello, I know nodejitsu.
View
@@ -29,27 +29,68 @@ vows.describe('forever-monitor/plugins/watch').addBatch({
assert.isTrue(child.watchIgnoreDotFiles);
assert.equal(watchDir, fs.realpathSync(child.watchDirectory));
},
'read .foreverignore file': {
'and store ignore patterns': function (child) {
setTimeout(function () {
assert.deepEqual(
child.watchIgnorePatterns,
fs.readFileSync(
path.join(watchDir, '.foreverignore'),
'utf8'
).split("\n").filter(Boolean)
);
}, 100);
'read .foreverignore file and store ignore patterns': function (child) {
setTimeout(function () {
assert.deepEqual(
child.watchIgnorePatterns,
fs.readFileSync(
path.join(watchDir, '.foreverignore'),
'utf8'
).split("\n").filter(Boolean)
);
}, 100);
}
}
}
}).addBatch({
'When using forever with watch enabled': {
'when a file matching an ignore pattern is added': {
topic: function () {
var self = this;
this.filenames = [
path.join(watchDir, 'ignore_newFile'),
path.join(watchDir, 'ignoredDir', 'ignore_subfile')
];
//
// Setup a bad restart function
//
function badRestart() {
this.callback(new Error('Monitor restarted at incorrect time.'));
}
monitor.once('restart', badRestart);
this.filenames.forEach(function (filename) {
fs.writeFileSync(filename, '');
});
//
// `chokidar` does not emit anything when ignored
// files have changed so we need a setTimeout here
// to prove that nothing has happened.
//
setTimeout(function () {
monitor.removeListener('restart', badRestart);
self.callback();
}, 5000);
},
'when file changes': {
topic: function (child) {
child.once('restart', this.callback);
fs.writeFileSync(path.join(watchDir, 'file'), '// hello, I know nodejitsu.');
},
'restart the script': function (child, _) {
fs.writeFileSync(path.join(watchDir, 'file'), '/* hello, I know nodejitsu. */');
}
'do nothing': function (err) {
assert.isUndefined(err);
this.filenames.forEach(function (filename) {
fs.unlinkSync(filename);
});
}
}
}
}).addBatch({
'When using forever with watch enabled': {
'when file changes': {
topic: function (child) {
child.once('restart', this.callback);
fs.writeFileSync(path.join(watchDir, 'file'), '// hello, I know nodejitsu.');
},
'restart the script': function (child, _) {
fs.writeFileSync(path.join(watchDir, 'file'), '/* hello, I know nodejitsu. ');
}
}
}
@@ -75,43 +116,6 @@ vows.describe('forever-monitor/plugins/watch').addBatch({
},
'restart the script': function (child, _) {
fs.writeFileSync(path.join(watchDir, 'removeMe'), '');
}
}
}
}).addBatch({
'When using forever with watch enabled': {
'when a file matching an ignore pattern is added': {
topic: function () {
var self = this;
this.expected = [];
this.filenames = [
path.join(watchDir, 'ignore_newFile'),
path.join(watchDir, 'ignoredDir', 'ignore_subfile')
];
monitor.on('watch:ignore', function (info) {
if (self.expected.indexOf(info.file) === -1) {
self.expected.push(info.file);
}
if (self.expected.length == 2) {
self.callback();
}
});
this.filenames.forEach(function (filename) {
fs.writeFileSync(filename, '');
});
},
'do nothing': function () {
var expected = this.expected;
assert.lengthOf(expected, 2);
this.filenames.forEach(function (filename) {
assert.include(expected, filename);
fs.unlinkSync(filename);
});
monitor.stop();
}
}

0 comments on commit 6ed022b

Please sign in to comment.