Skip to content

Commit

Permalink
updating test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Levin authored and Trott committed Jan 24, 2020
1 parent 7e23cef commit 120a471
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions test/parallel/test-fs-watch-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,34 @@ const filepathOne = path.join(testsubdir, filenameOne);
if (!common.isOSX && !common.isWindows) {
common.expectsError(() => fs.watch(testDir, { recursive: true }),
{ code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
} else {

testWhenRecursiveIsImplemented();
return;
}
const watcher = fs.watch(testDir, { recursive: true });

function testWhenRecursiveIsImplemented() {
const watcher = fs.watch(testDir, { recursive: true });

let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.ok(event === 'change' || event === 'rename');

// Ignore stale events generated by mkdir and other tests
if (filename !== relativePathOne)
return;
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.ok(event === 'change' || event === 'rename');

if (common.isOSX) {
clearInterval(interval);
}
watcher.close();
watcherClosed = true;
});
// Ignore stale events generated by mkdir and other tests
if (filename !== relativePathOne)
return;

let interval;
if (common.isOSX) {
interval = setInterval(function() {
fs.writeFileSync(filepathOne, 'world');
}, 10);
} else {
fs.writeFileSync(filepathOne, 'world');
clearInterval(interval);
}
watcher.close();
watcherClosed = true;
});

process.on('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
});
let interval;
if (common.isOSX) {
interval = setInterval(function() {
fs.writeFileSync(filepathOne, 'world');
}, 10);
} else {
fs.writeFileSync(filepathOne, 'world');
}

process.on('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
});

0 comments on commit 120a471

Please sign in to comment.