diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-16 06:40:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 01:40:30 -0400 |
commit | 5ac728a5f1af575d011c2143f5c9273b0fb4c5bb (patch) | |
tree | dfba0fdb3ba17989fd6c3af89ce17a0a71a4df0c /cli/js/tests/read_dir_test.ts | |
parent | 6441852a1d5eef0d05ed172a00bef58ad5988842 (diff) |
refactor(cli/js/ops/fs): Improve readdir() and FileInfo interfaces (#4763)
Diffstat (limited to 'cli/js/tests/read_dir_test.ts')
-rw-r--r-- | cli/js/tests/read_dir_test.ts | 15 |
1 files changed, 8 insertions, 7 deletions
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); |