fs.watch should not require a listener arguments

Since fs.watch returns an event emitter where the change event is exactly
the same as the listener callback, the argument should be required
This commit is contained in:
Andreas Madsen 2012-05-19 23:05:43 +02:00 committed by isaacs
parent 18b94ea838
commit a039bad299
3 changed files with 7 additions and 25 deletions

View File

@ -477,7 +477,7 @@ you need to compare `curr.mtime` and `prev.mtime`.
Stop watching for changes on `filename`.
## fs.watch(filename, [options], listener)
## fs.watch(filename, [options], [listener])
Stability: 2 - Unstable. Not available on all platforms.

View File

@ -773,16 +773,15 @@ fs.watch = function(filename) {
listener = arguments[1];
}
if (!listener) {
throw new Error('watch requires a listener function');
}
if (options.persistent === undefined) options.persistent = true;
watcher = new FSWatcher();
watcher.start(filename, options.persistent);
if (listener) {
watcher.addListener('change', listener);
}
return watcher;
};

View File

@ -58,18 +58,10 @@ try { fs.rmdirSync(testsubdir); } catch (e) { }
fs.writeFileSync(filepathOne, 'hello');
assert.throws(
function() {
fs.watch(filepathOne);
},
function(e) {
return e.message === 'watch requires a listener function';
}
);
assert.doesNotThrow(
function() {
var watcher = fs.watch(filepathOne, function(event, filename) {
var watcher = fs.watch(filepathOne)
watcher.on('change', function(event, filename) {
assert.equal('change', event);
if (expectFilePath) {
assert.equal('watch.txt', filename);
@ -91,15 +83,6 @@ process.chdir(testDir);
fs.writeFileSync(filepathTwoAbs, 'howdy');
assert.throws(
function() {
fs.watch(filepathTwo);
},
function(e) {
return e.message === 'watch requires a listener function';
}
);
assert.doesNotThrow(
function() {
var watcher = fs.watch(filepathTwo, function(event, filename) {