diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-07-08 16:31:07 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-07-09 15:48:43 +0200 |
commit | 5b5362aa8d80d0822f37e2448d024452dd3c0a98 (patch) | |
tree | a26aa6b3da32fcf3f8b54d6051894b857bc9216e /test/pummel | |
parent | bf539f9bfd2cde4c18557f2607455a4f44fc1565 (diff) | |
download | node-new-5b5362aa8d80d0822f37e2448d024452dd3c0a98.tar.gz |
fs: make unwatchFile() remove a specific listener
Before this commit, `fs.unwatchFile(path)` removed *all* listeners for `path`.
The function is overloaded now: `fs.unwatchFile(path)` still removes all
listeners, but `fs.unwatchFile(path, cb)` lets you remove a specific listener.
Fixes #3660.
Diffstat (limited to 'test/pummel')
-rw-r--r-- | test/pummel/test-fs-watch-file.js | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/test/pummel/test-fs-watch-file.js b/test/pummel/test-fs-watch-file.js index 3df28af56f..f3c5f5bb6a 100644 --- a/test/pummel/test-fs-watch-file.js +++ b/test/pummel/test-fs-watch-file.js @@ -26,6 +26,7 @@ var fs = require('fs'); var watchSeenOne = 0; var watchSeenTwo = 0; +var watchSeenThree = 0; var startDir = process.cwd(); var testDir = common.fixturesDir; @@ -37,12 +38,16 @@ var filenameTwo = 'hasOwnProperty'; var filepathTwo = filenameTwo; var filepathTwoAbs = path.join(testDir, filenameTwo); +var filenameThree = 'charm'; // because the third time is + process.on('exit', function() { fs.unlinkSync(filepathOne); fs.unlinkSync(filepathTwoAbs); + fs.unlinkSync(filenameThree); assert.equal(1, watchSeenOne); - assert.equal(1, watchSeenTwo); + assert.equal(2, watchSeenTwo); + assert.equal(1, watchSeenThree); }); @@ -86,13 +91,38 @@ assert.throws( assert.doesNotThrow( function() { - fs.watchFile(filepathTwo, function(curr, prev) { - fs.unwatchFile(filepathTwo); + function a(curr, prev) { + fs.unwatchFile(filepathTwo, a); ++watchSeenTwo; - }); + } + function b(curr, prev) { + fs.unwatchFile(filepathTwo, b); + ++watchSeenTwo; + } + fs.watchFile(filepathTwo, a); + fs.watchFile(filepathTwo, b); } ); setTimeout(function() { fs.writeFileSync(filepathTwoAbs, 'pardner'); }, 1000); + +assert.doesNotThrow( + function() { + function a(curr, prev) { + assert.ok(0); // should not run + } + function b(curr, prev) { + fs.unwatchFile(filenameThree, b); + ++watchSeenThree; + } + fs.watchFile(filenameThree, a); + fs.watchFile(filenameThree, b); + fs.unwatchFile(filenameThree, a); + } +); + +setTimeout(function() { + fs.writeFileSync(filenameThree, 'pardner'); +}, 1000); |