From 595700c993891ec8bf83f455a6602070ab8351ac Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 1 Jun 2021 15:35:06 +0900 Subject: feat: add FsWatcher interface (#10798) --- cli/tests/unit/fs_events_test.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'cli/tests') 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, + iter: Deno.FsWatcher, ): Promise { 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 { @@ -78,3 +80,21 @@ unitTest( assertEquals(events, []); }, ); + +unitTest( + { perms: { read: true, write: true } }, + async function watchFsClose(): Promise { + 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, []); + }, +); -- cgit v1.2.3