2024-04-19 14:52:14 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
if (common.isSunOS)
|
|
|
|
|
common.skip('SunOS behaves differently');
|
|
|
|
|
|
2024-04-24 05:29:49 +00:00
|
|
|
if (common.isIBMi)
|
|
|
|
|
common.skip('IBMi does not support `fs.watch()`');
|
|
|
|
|
|
2024-04-19 14:52:14 +02:00
|
|
|
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
|
2025-11-15 16:04:50 +01:00
|
|
|
setTimeout(common.mustCall(() => {
|
2024-04-19 14:52:14 +02:00
|
|
|
fs.rm(tmpdir.resolve('./parent/child'), { recursive: true }, common.mustCall());
|
2025-11-15 16:04:50 +01:00
|
|
|
}), common.platformTimeout(500));
|