Skip to content

Commit

Permalink
fix(ext/node): pass normalized watchFile handler to StatWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Mar 15, 2024
1 parent dae162f commit 7f0bfe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ext/node/polyfills/_fs/_fs_watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export function watchFile(
statWatchers.set(watchPath, stat);
}

stat.addListener("change", listener!);
stat.addListener("change", handler);
return stat;
}

Expand Down
17 changes: 15 additions & 2 deletions tests/unit_node/_fs/_fs_watch_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { watch } from "node:fs";
import { assertEquals } from "@std/assert/mod.ts";
import { Stats, unwatchFile, watch, watchFile } from "node:fs";
import { assert, assertEquals } from "@std/assert/mod.ts";

function wait(time: number) {
return new Promise((resolve) => {
Expand All @@ -25,3 +25,16 @@ Deno.test({
assertEquals(result.length >= 1, true);
},
});

Deno.test({
name: "watching a file with options",
async fn() {
const file = Deno.makeTempFileSync();
const watcher = watchFile(
file,
() => {},
);
await wait(100);
unwatchFile(file);
},
});

0 comments on commit 7f0bfe2

Please sign in to comment.