fix: rename watch event missing (#24893)

This PR ensures that we forward a `rename` event in our file watcher.
The rust lib we use combines that with the `modify` event.

This fixes a compatibility issue with Node too, which sends the `rename`
event as well.

Fixes https://github.com/denoland/deno/issues/24880
This commit is contained in:
Marvin Hagemeister 2024-08-07 18:15:57 +02:00 committed by GitHub
parent 59c9bd0800
commit 9d6da1036d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 2 deletions

View file

@ -70,6 +70,26 @@ Deno.test(
},
);
Deno.test(
{ permissions: { read: true, write: true } },
async function watchFsRename() {
const testDir = await makeTempDir();
const watcher = Deno.watchFs(testDir);
async function waitForRename() {
for await (const event of watcher) {
if (event.kind === "rename") {
break;
}
}
}
const eventPromise = waitForRename();
const file = testDir + "/file.txt";
await Deno.writeTextFile(file, "hello");
await Deno.rename(file, testDir + "/file2.txt");
await eventPromise;
},
);
// TODO(kt3k): This test is for the backward compatibility of `.return` method.
// This should be removed at 2.0
Deno.test(