mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
test: make fs watch test more stable
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
39e26ae2e5
commit
05e9cb6f22
1 file changed
+12
-11
@@ -28,7 +28,7 @@ if (common.isIBMi) {
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const assert = require('assert');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
tmpdir.refresh();
|
||||
|
||||
@@ -38,13 +38,14 @@ const filepath = path.join(testsubdir, 'watch.txt');
|
||||
|
||||
fs.mkdirSync(testsubdir, 0o700);
|
||||
|
||||
// Need a grace period, else the mkdirSync() above fires off an event.
|
||||
setTimeout(function() {
|
||||
const watcher = fs.watch(testDir, { persistent: true }, common.mustNotCall());
|
||||
setTimeout(function() {
|
||||
fs.writeFileSync(filepath, 'test');
|
||||
}, 100);
|
||||
setTimeout(function() {
|
||||
watcher.close();
|
||||
}, 500);
|
||||
}, 50);
|
||||
const watcher = fs.watch(testDir, { persistent: true }, (event, filename) => {
|
||||
// This function may be called with the directory depending on timing but
|
||||
// must not be called with the file..
|
||||
assert.strictEqual(filename, 'testsubdir');
|
||||
});
|
||||
setTimeout(() => {
|
||||
fs.writeFileSync(filepath, 'test');
|
||||
}, 100);
|
||||
setTimeout(() => {
|
||||
watcher.close();
|
||||
}, 500);
|
||||
Reference in new issue
Block a user