Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10b68ed

Browse filesBrowse files
Ceres6aduh95
authored andcommitted
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: #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>
1 parent 9dbb255 commit 10b68ed
Copy full SHA for 10b68ed
Expand file treeCollapse file tree

5 files changed

+16
-32
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file-to-existing-subfolder.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ const relativePath = path.join(file, path.basename(subfolderPath), childrenFile)
4040
const watcher = fs.watch(testDirectory, { recursive: true });
4141
let watcherClosed = false;
4242
watcher.on('change', function(event, filename) {
43-
assert.strictEqual(event, 'rename');
44-
4543
if (filename === relativePath) {
44+
assert.strictEqual(event, 'rename');
4645
watcher.close();
4746
watcherClosed = true;
4847
}
Collapse file

‎test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file-to-new-folder.js
+12-24Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,20 @@ const childrenAbsolutePath = path.join(filePath, childrenFile);
3333
const childrenRelativePath = path.join(path.basename(filePath), childrenFile);
3434
let watcherClosed = false;
3535

36-
function doWatch() {
37-
const watcher = fs.watch(testDirectory, { recursive: true });
38-
watcher.on('change', function(event, filename) {
36+
const watcher = fs.watch(testDirectory, { recursive: true });
37+
watcher.on('change', function(event, filename) {
38+
if (filename === childrenRelativePath) {
3939
assert.strictEqual(event, 'rename');
40-
assert.ok(filename === path.basename(filePath) || filename === childrenRelativePath);
41-
42-
if (filename === childrenRelativePath) {
43-
watcher.close();
44-
watcherClosed = true;
45-
}
46-
});
47-
48-
// Do the write with a delay to ensure that the OS is ready to notify us.
49-
setTimeout(() => {
50-
fs.mkdirSync(filePath);
51-
fs.writeFileSync(childrenAbsolutePath, 'world');
52-
}, common.platformTimeout(200));
53-
}
40+
watcher.close();
41+
watcherClosed = true;
42+
}
43+
});
5444

55-
if (common.isMacOS) {
56-
// On macOS delay watcher start to avoid leaking previous events.
57-
// Refs: https://github.com/libuv/libuv/pull/4503
58-
setTimeout(doWatch, common.platformTimeout(100));
59-
} else {
60-
doWatch();
61-
}
45+
// Do the write with a delay to ensure that the OS is ready to notify us.
46+
setTimeout(() => {
47+
fs.mkdirSync(filePath);
48+
fs.writeFileSync(childrenAbsolutePath, 'world');
49+
}, common.platformTimeout(200));
6250

6351
process.once('exit', function() {
6452
assert(watcherClosed, 'watcher Object was not closed');
Collapse file

‎test/parallel/test-fs-watch-recursive-add-file-with-url.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file-with-url.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ tmpdir.refresh();
3535
const watcher = fs.watch(url, { recursive: true });
3636
let watcherClosed = false;
3737
watcher.on('change', function(event, filename) {
38-
assert.strictEqual(event, 'rename');
39-
4038
if (filename === path.basename(filePath)) {
39+
assert.strictEqual(event, 'rename');
4140
watcher.close();
4241
watcherClosed = true;
4342
}
Collapse file

‎test/parallel/test-fs-watch-recursive-add-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-file.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ const testFile = path.join(testDirectory, 'file-1.txt');
3131
const watcher = fs.watch(testDirectory, { recursive: true });
3232
let watcherClosed = false;
3333
watcher.on('change', function(event, filename) {
34-
assert.strictEqual(event, 'rename');
35-
3634
if (filename === path.basename(testFile)) {
35+
assert.strictEqual(event, 'rename');
3736
watcher.close();
3837
watcherClosed = true;
3938
}
Collapse file

‎test/parallel/test-fs-watch-recursive-add-folder.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-watch-recursive-add-folder.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ tmpdir.refresh();
3333
const watcher = fs.watch(testDirectory, { recursive: true });
3434
let watcherClosed = false;
3535
watcher.on('change', function(event, filename) {
36-
assert.strictEqual(event, 'rename');
37-
3836
if (filename === path.basename(testFile)) {
37+
assert.strictEqual(event, 'rename');
3938
watcher.close();
4039
watcherClosed = true;
4140
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.