mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: ignore unrelated events in FW watch tests
Change assertions on `test-fs-watch-recursive-add-*` tests to only take into account change events that match the file. PR-URL: https://github.com/nodejs/node/pull/55605 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
4da8d110f3
commit
42f465972a
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
watcher.close();
|
||||
watcherClosed = true;
|
||||
}
|
||||
});
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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');
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user