Skip to content

Commit 78cd453

Browse files
committed
test: make fs-watch-recursive less racy
FSEventStream may emit events that happened right before it has started. Ignore changes emitted for the directory itself, since they may come from the stale events.
1 parent 259d449 commit 78cd453

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/simple/test-fs-watch-recursive.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ if (process.platform === 'darwin') {
3030
var testDir = common.tmpDir;
3131

3232
var filenameOne = 'watch.txt';
33-
var testsubdir = path.join(testDir, 'testsubdir');
33+
var testsubdirName = 'testsubdir';
34+
var testsubdir = path.join(testDir, testsubdirName);
3435
var relativePathOne = path.join('testsubdir', filenameOne);
3536
var filepathOne = path.join(testsubdir, filenameOne);
3637

@@ -44,12 +45,16 @@ if (process.platform === 'darwin') {
4445
};
4546

4647
try { fs.mkdirSync(testsubdir, 0700); } catch (e) {}
47-
fs.writeFileSync(filepathOne, 'hello');
4848

4949
assert.doesNotThrow(function() {
5050
var watcher = fs.watch(testDir, {recursive: true});
5151
watcher.on('change', function(event, filename) {
5252
assert.ok('change' === event || 'rename' === event);
53+
54+
// Ignore stale events generated by mkdir
55+
if (filename === testsubdirName)
56+
return;
57+
5358
assert.equal(relativePathOne, filename);
5459

5560
watcher.close();

0 commit comments

Comments
 (0)