diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2021-06-01 15:35:06 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-01 15:35:06 +0900 |
commit | 595700c993891ec8bf83f455a6602070ab8351ac (patch) | |
tree | 64f292aafc9fac62909c81a43429f89590d3be56 /cli/tests | |
parent | f8913680573505e45f0c094af1421f7a4abb4fb2 (diff) |
feat: add FsWatcher interface (#10798)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/fs_events_test.ts | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cli/tests/unit/fs_events_test.ts b/cli/tests/unit/fs_events_test.ts index 0b30a070d..87f3ec241 100644 --- a/cli/tests/unit/fs_events_test.ts +++ b/cli/tests/unit/fs_events_test.ts @@ -26,7 +26,7 @@ unitTest({ perms: { read: true } }, function watchFsInvalidPath() { }); async function getTwoEvents( - iter: AsyncIterableIterator<Deno.FsEvent>, + iter: Deno.FsWatcher, ): Promise<Deno.FsEvent[]> { const events = []; for await (const event of iter) { @@ -61,6 +61,8 @@ unitTest( }, ); +// TODO(kt3k): This test is for the backward compatibility of `.return` method. +// This should be removed at 2.0 unitTest( { perms: { read: true, write: true } }, async function watchFsReturn(): Promise<void> { @@ -78,3 +80,21 @@ unitTest( assertEquals(events, []); }, ); + +unitTest( + { perms: { read: true, write: true } }, + async function watchFsClose(): Promise<void> { + const testDir = await Deno.makeTempDir(); + const iter = Deno.watchFs(testDir); + + // Asynchronously loop events. + const eventsPromise = getTwoEvents(iter); + + // Close the watcher. + await iter.close(); + + // Expect zero events. + const events = await eventsPromise; + assertEquals(events, []); + }, +); |