mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
ddd0a9e494
PR-URL: https://github.com/nodejs/node/pull/52645 Refs: https://github.com/nodejs/node/issues/52640 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
34 lines
1012 B
JavaScript
34 lines
1012 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const fs = require('fs');
|
|
|
|
if (common.isSunOS)
|
|
common.skip('SunOS behaves differently');
|
|
|
|
if (common.isIBMi)
|
|
common.skip('IBMi does not support `fs.watch()`');
|
|
|
|
tmpdir.refresh();
|
|
|
|
fs.mkdirSync(tmpdir.resolve('./parent/child'), { recursive: true });
|
|
|
|
fs.writeFileSync(tmpdir.resolve('./parent/child/test.tmp'), 'test');
|
|
|
|
const toWatch = tmpdir.resolve('./parent');
|
|
|
|
const onFileUpdate = common.mustCallAtLeast((eventType, filename) => {
|
|
// We are only checking for the filename to avoid having Windows, Linux and Mac specific assertions
|
|
if (fs.readdirSync(tmpdir.resolve('./parent')).length === 0) {
|
|
watcher.close();
|
|
}
|
|
}, 1);
|
|
|
|
const watcher = fs.watch(toWatch, { recursive: true }, onFileUpdate);
|
|
|
|
// We must wait a bit `fs.rm()` to let the watcher be set up properly
|
|
setTimeout(() => {
|
|
fs.rm(tmpdir.resolve('./parent/child'), { recursive: true }, common.mustCall());
|
|
}, common.platformTimeout(500));
|