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 951d299

Browse filesBrowse files
benjamingrdanielleadams
authored andcommitted
test: make fs watch test more stable
PR-URL: #41715 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2eabfdd commit 951d299
Copy full SHA for 951d299

File tree

Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-11
lines changed
Open diff view settings
Collapse file

‎test/pummel/test-fs-watch-non-recursive.js‎

Copy file name to clipboardExpand all lines: test/pummel/test-fs-watch-non-recursive.js
+12-11Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if (common.isIBMi) {
2828

2929
const path = require('path');
3030
const fs = require('fs');
31-
31+
const assert = require('assert');
3232
const tmpdir = require('../common/tmpdir');
3333
tmpdir.refresh();
3434

@@ -38,13 +38,14 @@ const filepath = path.join(testsubdir, 'watch.txt');
3838

3939
fs.mkdirSync(testsubdir, 0o700);
4040

41-
// Need a grace period, else the mkdirSync() above fires off an event.
42-
setTimeout(function() {
43-
const watcher = fs.watch(testDir, { persistent: true }, common.mustNotCall());
44-
setTimeout(function() {
45-
fs.writeFileSync(filepath, 'test');
46-
}, 100);
47-
setTimeout(function() {
48-
watcher.close();
49-
}, 500);
50-
}, 50);
41+
const watcher = fs.watch(testDir, { persistent: true }, (event, filename) => {
42+
// This function may be called with the directory depending on timing but
43+
// must not be called with the file..
44+
assert.strictEqual(filename, 'testsubdir');
45+
});
46+
setTimeout(() => {
47+
fs.writeFileSync(filepath, 'test');
48+
}, 100);
49+
setTimeout(() => {
50+
watcher.close();
51+
}, 500);

0 commit comments

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