Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ const relativePath = path.join(file, path.basename(subfolderPath), childrenFile)
const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');

if (filename === relativePath) {
assert.strictEqual(event, 'rename');
watcher.close();
watcherClosed = true;
}
Expand Down
36 changes: 12 additions & 24 deletions test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,20 @@ const childrenAbsolutePath = path.join(filePath, childrenFile);
const childrenRelativePath = path.join(path.basename(filePath), childrenFile);
let watcherClosed = false;

function doWatch() {
const watcher = fs.watch(testDirectory, { recursive: true });
watcher.on('change', function(event, filename) {
const watcher = fs.watch(testDirectory, { recursive: true });
watcher.on('change', function(event, filename) {
if (filename === childrenRelativePath) {
assert.strictEqual(event, 'rename');
assert.ok(filename === path.basename(filePath) || filename === childrenRelativePath);

if (filename === childrenRelativePath) {
watcher.close();
watcherClosed = true;
}
});

// Do the write with a delay to ensure that the OS is ready to notify us.
setTimeout(() => {
fs.mkdirSync(filePath);
fs.writeFileSync(childrenAbsolutePath, 'world');
}, common.platformTimeout(200));
}
watcher.close();
watcherClosed = true;
}
});

if (common.isMacOS) {
// On macOS delay watcher start to avoid leaking previous events.
// Refs: https://github.com/libuv/libuv/pull/4503
setTimeout(doWatch, common.platformTimeout(100));
} else {
doWatch();
}
// Do the write with a delay to ensure that the OS is ready to notify us.
setTimeout(() => {
fs.mkdirSync(filePath);
fs.writeFileSync(childrenAbsolutePath, 'world');
}, common.platformTimeout(200));

process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-watch-recursive-add-file-with-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ tmpdir.refresh();
const watcher = fs.watch(url, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');

if (filename === path.basename(filePath)) {
assert.strictEqual(event, 'rename');
watcher.close();
watcherClosed = true;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-watch-recursive-add-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ const testFile = path.join(testDirectory, 'file-1.txt');
const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');

if (filename === path.basename(testFile)) {
assert.strictEqual(event, 'rename');
watcher.close();
watcherClosed = true;
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-watch-recursive-add-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ tmpdir.refresh();
const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');

if (filename === path.basename(testFile)) {
assert.strictEqual(event, 'rename');
watcher.close();
watcherClosed = true;
}
Expand Down
Loading