diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-03-15 21:14:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 09:44:47 +0530 |
commit | 9c5ddf7c69f0d3ddaa93b194f0020944569e0e3e (patch) | |
tree | bc5fd51663b842ed11f6562c71e842219d479bef | |
parent | ab67b4c645dc34619e09c2f9f36c18122b11a307 (diff) |
fix(ext/node): pass normalized watchFile handler to StatWatcher (#22940)
Fixes https://github.com/denoland/deno/issues/22939
-rw-r--r-- | ext/node/polyfills/_fs/_fs_watch.ts | 2 | ||||
-rw-r--r-- | tests/unit_node/_fs/_fs_watch_test.ts | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/ext/node/polyfills/_fs/_fs_watch.ts b/ext/node/polyfills/_fs/_fs_watch.ts index 78903cd55..e94818da9 100644 --- a/ext/node/polyfills/_fs/_fs_watch.ts +++ b/ext/node/polyfills/_fs/_fs_watch.ts @@ -211,7 +211,7 @@ export function watchFile( statWatchers.set(watchPath, stat); } - stat.addListener("change", listener!); + stat.addListener("change", handler); return stat; } diff --git a/tests/unit_node/_fs/_fs_watch_test.ts b/tests/unit_node/_fs/_fs_watch_test.ts index 01df80f97..01236a493 100644 --- a/tests/unit_node/_fs/_fs_watch_test.ts +++ b/tests/unit_node/_fs/_fs_watch_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { watch } from "node:fs"; +import { unwatchFile, watch, watchFile } from "node:fs"; import { assertEquals } from "@std/assert/mod.ts"; function wait(time: number) { @@ -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(); + watchFile( + file, + () => {}, + ); + await wait(100); + unwatchFile(file); + }, +}); |