From 5ac728a5f1af575d011c2143f5c9273b0fb4c5bb Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 16 Apr 2020 06:40:30 +0100 Subject: refactor(cli/js/ops/fs): Improve readdir() and FileInfo interfaces (#4763) --- cli/js/tests/read_dir_test.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'cli/js/tests/read_dir_test.ts') diff --git a/cli/js/tests/read_dir_test.ts b/cli/js/tests/read_dir_test.ts index 95936c645..2c7f42103 100644 --- a/cli/js/tests/read_dir_test.ts +++ b/cli/js/tests/read_dir_test.ts @@ -1,14 +1,12 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { unitTest, assert, assertEquals } from "./test_util.ts"; -type FileInfo = Deno.FileInfo; - -function assertSameContent(files: FileInfo[]): void { +function assertSameContent(files: Deno.DirEntry[]): void { let counter = 0; for (const file of files) { if (file.name === "subdir") { - assert(file.isDirectory()); + assert(file.isDirectory); counter++; } @@ -22,7 +20,7 @@ function assertSameContent(files: FileInfo[]): void { } unitTest({ perms: { read: true } }, function readdirSyncSuccess(): void { - const files = Deno.readdirSync("cli/tests/"); + const files = [...Deno.readdirSync("cli/tests/")]; assertSameContent(files); }); @@ -68,7 +66,10 @@ unitTest({ perms: { read: true } }, function readdirSyncNotFound(): void { unitTest({ perms: { read: true } }, async function readdirSuccess(): Promise< void > { - const files = await Deno.readdir("cli/tests/"); + const files = []; + for await (const dirEntry of Deno.readdir("cli/tests/")) { + files.push(dirEntry); + } assertSameContent(files); }); @@ -77,7 +78,7 @@ unitTest({ perms: { read: false } }, async function readdirPerm(): Promise< > { let caughtError = false; try { - await Deno.readdir("tests/"); + await Deno.readdir("tests/")[Symbol.asyncIterator]().next(); } catch (e) { caughtError = true; assert(e instanceof Deno.errors.PermissionDenied); -- cgit v1.2.3