Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Jan 19, 2024
commit 00ce83355b4fc9c075b4051c19c72b501447c3ac
44 changes: 26 additions & 18 deletions test/parallel/test-fs-watch-recursive-add-folder.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'use strict';

const common = require('../common');
const { setTimeout } = require('timers/promises');

if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

// fs-watch on folders have limited capability in AIX.
// The testcase makes use of folder watching, and causes
// hang. This behavior is documented. Skip this for AIX.

if (common.isAIX)
common.skip('folder watch capability is limited in AIX.');

Expand All @@ -16,27 +21,30 @@ const tmpdir = require('../common/tmpdir');
const testDir = tmpdir.path;
tmpdir.refresh();

// Add a folder to already watching folder
(async () => {
// Add a folder to already watching folder

const rootDirectory = fs.mkdtempSync(testDir + path.sep);
const testDirectory = path.join(rootDirectory, 'test-2');
fs.mkdirSync(testDirectory);
const rootDirectory = fs.mkdtempSync(testDir + path.sep);
const testDirectory = path.join(rootDirectory, 'test-2');
fs.mkdirSync(testDirectory);

const testFile = path.join(testDirectory, 'folder-2');
const testFile = path.join(testDirectory, 'folder-2');

const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');
const watcher = fs.watch(testDirectory, { recursive: true });
let watcherClosed = false;
watcher.on('change', function(event, filename) {
assert.strictEqual(event, 'rename');

if (filename === path.basename(testFile)) {
watcher.close();
watcherClosed = true;
}
});
if (filename === path.basename(testFile)) {
watcher.close();
watcherClosed = true;
}
});

fs.mkdirSync(testFile);
await setTimeout(common.platformTimeout(100));
fs.mkdirSync(testFile);

process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
});
process.once('exit', function() {
assert(watcherClosed, 'watcher Object was not closed');
});
})().then(common.mustCall());