summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/empty_dir_test.ts40
-rw-r--r--fs/ensure_dir_test.ts54
-rw-r--r--fs/ensure_file_test.ts64
-rw-r--r--fs/ensure_link_test.ts32
-rw-r--r--fs/ensure_symlink_test.ts62
-rw-r--r--fs/eol.ts2
-rw-r--r--fs/eol_test.ts10
-rw-r--r--fs/exists.ts4
-rw-r--r--fs/exists_test.ts12
-rw-r--r--fs/glob_test.ts27
-rw-r--r--fs/globrex_test.ts40
-rw-r--r--fs/move_test.ts78
-rw-r--r--fs/read_file_str_test.ts4
-rw-r--r--fs/read_json.ts4
-rw-r--r--fs/read_json_test.ts72
-rw-r--r--fs/utils.ts2
-rw-r--r--fs/utils_test.ts8
-rw-r--r--fs/walk.ts17
-rw-r--r--fs/walk_test.ts82
-rw-r--r--fs/write_file_str_test.ts4
-rw-r--r--fs/write_json_test.ts40
21 files changed, 367 insertions, 291 deletions
diff --git a/fs/empty_dir_test.ts b/fs/empty_dir_test.ts
index d91c497a7..b44e600d7 100644
--- a/fs/empty_dir_test.ts
+++ b/fs/empty_dir_test.ts
@@ -10,7 +10,7 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function emptyDirIfItNotExist() {
+test(async function emptyDirIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "empty_dir_test_1");
const testNestDir = path.join(testDir, "nest");
// empty a dir which not exist. then it will create new one
@@ -26,7 +26,7 @@ test(async function emptyDirIfItNotExist() {
}
});
-test(function emptyDirSyncIfItNotExist() {
+test(function emptyDirSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "empty_dir_test_2");
const testNestDir = path.join(testDir, "nest");
// empty a dir which not exist. then it will create new one
@@ -42,7 +42,7 @@ test(function emptyDirSyncIfItNotExist() {
}
});
-test(async function emptyDirIfItExist() {
+test(async function emptyDirIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "empty_dir_test_3");
const testNestDir = path.join(testDir, "nest");
// create test dir
@@ -67,21 +67,25 @@ test(async function emptyDirIfItExist() {
assertEquals(stat.isDirectory(), true);
// nest directory have been remove
- await assertThrowsAsync(async () => {
- await Deno.stat(testNestDir);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testNestDir);
+ }
+ );
// test file have been remove
- await assertThrowsAsync(async () => {
- await Deno.stat(testDirFile);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testDirFile);
+ }
+ );
} finally {
// remote test dir
await Deno.remove(testDir, { recursive: true });
}
});
-test(function emptyDirSyncIfItExist() {
+test(function emptyDirSyncIfItExist(): void {
const testDir = path.join(testdataDir, "empty_dir_test_4");
const testNestDir = path.join(testDir, "nest");
// create test dir
@@ -106,14 +110,18 @@ test(function emptyDirSyncIfItExist() {
assertEquals(stat.isDirectory(), true);
// nest directory have been remove
- assertThrows(() => {
- Deno.statSync(testNestDir);
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testNestDir);
+ }
+ );
// test file have been remove
- assertThrows(() => {
- Deno.statSync(testDirFile);
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testDirFile);
+ }
+ );
} finally {
// remote test dir
Deno.removeSync(testDir, { recursive: true });
diff --git a/fs/ensure_dir_test.ts b/fs/ensure_dir_test.ts
index 3426588b7..ad34336dc 100644
--- a/fs/ensure_dir_test.ts
+++ b/fs/ensure_dir_test.ts
@@ -7,22 +7,26 @@ import { ensureFile, ensureFileSync } from "./ensure_file.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function ensureDirIfItNotExist() {
+test(async function ensureDirIfItNotExist(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_not_exist");
const testDir = path.join(baseDir, "test");
await ensureDir(testDir);
- await assertThrowsAsync(async () => {
- await Deno.stat(testDir).then(() => {
- throw new Error("test dir should exists.");
- });
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testDir).then(
+ (): void => {
+ throw new Error("test dir should exists.");
+ }
+ );
+ }
+ );
await Deno.remove(baseDir, { recursive: true });
});
-test(function ensureDirSyncIfItNotExist() {
+test(function ensureDirSyncIfItNotExist(): void {
const baseDir = path.join(testdataDir, "ensure_dir_sync_not_exist");
const testDir = path.join(baseDir, "test");
@@ -33,7 +37,7 @@ test(function ensureDirSyncIfItNotExist() {
Deno.removeSync(baseDir, { recursive: true });
});
-test(async function ensureDirIfItExist() {
+test(async function ensureDirIfItExist(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_exist");
const testDir = path.join(baseDir, "test");
@@ -42,16 +46,20 @@ test(async function ensureDirIfItExist() {
await ensureDir(testDir);
- await assertThrowsAsync(async () => {
- await Deno.stat(testDir).then(() => {
- throw new Error("test dir should still exists.");
- });
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testDir).then(
+ (): void => {
+ throw new Error("test dir should still exists.");
+ }
+ );
+ }
+ );
await Deno.remove(baseDir, { recursive: true });
});
-test(function ensureDirSyncIfItExist() {
+test(function ensureDirSyncIfItExist(): void {
const baseDir = path.join(testdataDir, "ensure_dir_sync_exist");
const testDir = path.join(baseDir, "test");
@@ -60,22 +68,24 @@ test(function ensureDirSyncIfItExist() {
ensureDirSync(testDir);
- assertThrows(() => {
- Deno.statSync(testDir);
- throw new Error("test dir should still exists.");
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testDir);
+ throw new Error("test dir should still exists.");
+ }
+ );
Deno.removeSync(baseDir, { recursive: true });
});
-test(async function ensureDirIfItAsFile() {
+test(async function ensureDirIfItAsFile(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file");
const testFile = path.join(baseDir, "test");
await ensureFile(testFile);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await ensureDir(testFile);
},
Error,
@@ -85,14 +95,14 @@ test(async function ensureDirIfItAsFile() {
await Deno.remove(baseDir, { recursive: true });
});
-test(function ensureDirSyncIfItAsFile() {
+test(function ensureDirSyncIfItAsFile(): void {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file_async");
const testFile = path.join(baseDir, "test");
ensureFileSync(testFile);
assertThrows(
- () => {
+ (): void => {
ensureDirSync(testFile);
},
Error,
diff --git a/fs/ensure_file_test.ts b/fs/ensure_file_test.ts
index fd3f4718a..fa27133ab 100644
--- a/fs/ensure_file_test.ts
+++ b/fs/ensure_file_test.ts
@@ -6,36 +6,42 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function ensureFileIfItNotExist() {
+test(async function ensureFileIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_1");
const testFile = path.join(testDir, "test.txt");
await ensureFile(testFile);
- await assertThrowsAsync(async () => {
- await Deno.stat(testFile).then(() => {
- throw new Error("test file should exists.");
- });
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testFile).then(
+ (): void => {
+ throw new Error("test file should exists.");
+ }
+ );
+ }
+ );
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureFileSyncIfItNotExist() {
+test(function ensureFileSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "ensure_file_2");
const testFile = path.join(testDir, "test.txt");
ensureFileSync(testFile);
- assertThrows(() => {
- Deno.statSync(testFile);
- throw new Error("test file should exists.");
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testFile);
+ throw new Error("test file should exists.");
+ }
+ );
Deno.removeSync(testDir, { recursive: true });
});
-test(async function ensureFileIfItExist() {
+test(async function ensureFileIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_3");
const testFile = path.join(testDir, "test.txt");
@@ -44,16 +50,20 @@ test(async function ensureFileIfItExist() {
await ensureFile(testFile);
- await assertThrowsAsync(async () => {
- await Deno.stat(testFile).then(() => {
- throw new Error("test file should exists.");
- });
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testFile).then(
+ (): void => {
+ throw new Error("test file should exists.");
+ }
+ );
+ }
+ );
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureFileSyncIfItExist() {
+test(function ensureFileSyncIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_file_4");
const testFile = path.join(testDir, "test.txt");
@@ -62,21 +72,23 @@ test(function ensureFileSyncIfItExist() {
ensureFileSync(testFile);
- assertThrows(() => {
- Deno.statSync(testFile);
- throw new Error("test file should exists.");
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testFile);
+ throw new Error("test file should exists.");
+ }
+ );
Deno.removeSync(testDir, { recursive: true });
});
-test(async function ensureFileIfItExistAsDir() {
+test(async function ensureFileIfItExistAsDir(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_5");
await Deno.mkdir(testDir, true);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await ensureFile(testDir);
},
Error,
@@ -86,13 +98,13 @@ test(async function ensureFileIfItExistAsDir() {
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureFileSyncIfItExistAsDir() {
+test(function ensureFileSyncIfItExistAsDir(): void {
const testDir = path.join(testdataDir, "ensure_file_6");
Deno.mkdirSync(testDir, true);
assertThrows(
- () => {
+ (): void => {
ensureFileSync(testDir);
},
Error,
diff --git a/fs/ensure_link_test.ts b/fs/ensure_link_test.ts
index 02beaa87d..8d14f34ec 100644
--- a/fs/ensure_link_test.ts
+++ b/fs/ensure_link_test.ts
@@ -11,32 +11,36 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function ensureLinkIfItNotExist() {
+test(async function ensureLinkIfItNotExist(): Promise<void> {
const srcDir = path.join(testdataDir, "ensure_link_1");
const destDir = path.join(testdataDir, "ensure_link_1_2");
const testFile = path.join(srcDir, "test.txt");
const linkFile = path.join(destDir, "link.txt");
- await assertThrowsAsync(async () => {
- await ensureLink(testFile, linkFile);
- });
+ await assertThrowsAsync(
+ (): Promise<void> => {
+ await ensureLink(testFile, linkFile);
+ }
+ );
await Deno.remove(destDir, { recursive: true });
});
-test(function ensureLinkSyncIfItNotExist() {
+test(function ensureLinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "ensure_link_2");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
- assertThrows(() => {
- ensureLinkSync(testFile, linkFile);
- });
+ assertThrows(
+ (): void => {
+ ensureLinkSync(testFile, linkFile);
+ }
+ );
Deno.removeSync(testDir, { recursive: true });
});
-test(async function ensureLinkIfItExist() {
+test(async function ensureLinkIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_link_3");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@@ -83,7 +87,7 @@ test(async function ensureLinkIfItExist() {
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureLinkSyncIfItExist() {
+test(function ensureLinkSyncIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_link_4");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@@ -131,7 +135,7 @@ test(function ensureLinkSyncIfItExist() {
Deno.removeSync(testDir, { recursive: true });
});
-test(async function ensureLinkDirectoryIfItExist() {
+test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_link_origin_3");
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");
@@ -140,7 +144,7 @@ test(async function ensureLinkDirectoryIfItExist() {
await Deno.writeFile(testFile, new Uint8Array());
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await ensureLink(testDir, linkDir);
},
Deno.DenoError,
@@ -150,7 +154,7 @@ test(async function ensureLinkDirectoryIfItExist() {
Deno.removeSync(testDir, { recursive: true });
});
-test(function ensureLinkSyncDirectoryIfItExist() {
+test(function ensureLinkSyncDirectoryIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_link_origin_3");
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");
@@ -159,7 +163,7 @@ test(function ensureLinkSyncDirectoryIfItExist() {
Deno.writeFileSync(testFile, new Uint8Array());
assertThrows(
- () => {
+ (): void => {
ensureLinkSync(testDir, linkDir);
},
Deno.DenoError,
diff --git a/fs/ensure_symlink_test.ts b/fs/ensure_symlink_test.ts
index 22be30b88..d769615fb 100644
--- a/fs/ensure_symlink_test.ts
+++ b/fs/ensure_symlink_test.ts
@@ -12,36 +12,46 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
const isWindows = Deno.platform.os === "win";
-test(async function ensureSymlinkIfItNotExist() {
+test(async function ensureSymlinkIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_1");
const testFile = path.join(testDir, "test.txt");
- assertThrowsAsync(async () => {
- await ensureSymlink(testFile, path.join(testDir, "test1.txt"));
- });
-
- assertThrowsAsync(async () => {
- await Deno.stat(testFile).then(() => {
- throw new Error("test file should exists.");
- });
- });
+ assertThrowsAsync(
+ async (): Promise<void> => {
+ await ensureSymlink(testFile, path.join(testDir, "test1.txt"));
+ }
+ );
+
+ assertThrowsAsync(
+ async (): Promise<void> => {
+ await Deno.stat(testFile).then(
+ (): void => {
+ throw new Error("test file should exists.");
+ }
+ );
+ }
+ );
});
-test(function ensureSymlinkSyncIfItNotExist() {
+test(function ensureSymlinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "link_file_2");
const testFile = path.join(testDir, "test.txt");
- assertThrows(() => {
- ensureSymlinkSync(testFile, path.join(testDir, "test1.txt"));
- });
+ assertThrows(
+ (): void => {
+ ensureSymlinkSync(testFile, path.join(testDir, "test1.txt"));
+ }
+ );
- assertThrows(() => {
- Deno.statSync(testFile);
- throw new Error("test file should exists.");
- });
+ assertThrows(
+ (): void => {
+ Deno.statSync(testFile);
+ throw new Error("test file should exists.");
+ }
+ );
});
-test(async function ensureSymlinkIfItExist() {
+test(async function ensureSymlinkIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_3");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@@ -51,7 +61,7 @@ test(async function ensureSymlinkIfItExist() {
if (isWindows) {
await assertThrowsAsync(
- () => ensureSymlink(testFile, linkFile),
+ (): Promise<void> => ensureSymlink(testFile, linkFile),
Error,
"Not implemented"
);
@@ -70,7 +80,7 @@ test(async function ensureSymlinkIfItExist() {
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureSymlinkSyncIfItExist() {
+test(function ensureSymlinkSyncIfItExist(): void {
const testDir = path.join(testdataDir, "link_file_4");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@@ -80,7 +90,7 @@ test(function ensureSymlinkSyncIfItExist() {
if (isWindows) {
assertThrows(
- () => ensureSymlinkSync(testFile, linkFile),
+ (): void => ensureSymlinkSync(testFile, linkFile),
Error,
"Not implemented"
);
@@ -100,7 +110,7 @@ test(function ensureSymlinkSyncIfItExist() {
Deno.removeSync(testDir, { recursive: true });
});
-test(async function ensureSymlinkDirectoryIfItExist() {
+test(async function ensureSymlinkDirectoryIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_origin_3");
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");
@@ -110,7 +120,7 @@ test(async function ensureSymlinkDirectoryIfItExist() {
if (isWindows) {
await assertThrowsAsync(
- () => ensureSymlink(testDir, linkDir),
+ (): Promise<void> => ensureSymlink(testDir, linkDir),
Error,
"Not implemented"
);
@@ -132,7 +142,7 @@ test(async function ensureSymlinkDirectoryIfItExist() {
await Deno.remove(testDir, { recursive: true });
});
-test(function ensureSymlinkSyncDirectoryIfItExist() {
+test(function ensureSymlinkSyncDirectoryIfItExist(): void {
const testDir = path.join(testdataDir, "link_file_origin_3");
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");
@@ -142,7 +152,7 @@ test(function ensureSymlinkSyncDirectoryIfItExist() {
if (isWindows) {
assertThrows(
- () => ensureSymlinkSync(testDir, linkDir),
+ (): void => ensureSymlinkSync(testDir, linkDir),
Error,
"Not implemented"
);
diff --git a/fs/eol.ts b/fs/eol.ts
index 46babe406..55d03fa83 100644
--- a/fs/eol.ts
+++ b/fs/eol.ts
@@ -17,7 +17,7 @@ export function detect(content: string): EOL | null {
if (!d || d.length === 0) {
return null;
}
- const crlf = d.filter((x: string) => x === EOL.CRLF);
+ const crlf = d.filter((x: string): boolean => x === EOL.CRLF);
if (crlf.length > 0) {
return EOL.CRLF;
} else {
diff --git a/fs/eol_test.ts b/fs/eol_test.ts
index 94ca48627..4669c795a 100644
--- a/fs/eol_test.ts
+++ b/fs/eol_test.ts
@@ -11,28 +11,28 @@ const NoNLinput = "deno is not node";
test({
name: "[EOL] Detect CR LF",
- fn() {
+ fn(): void {
assertEquals(detect(CRLFinput), EOL.CRLF);
}
});
test({
name: "[EOL] Detect LF",
- fn() {
+ fn(): void {
assertEquals(detect(LFinput), EOL.LF);
}
});
test({
name: "[EOL] Detect No New Line",
- fn() {
+ fn(): void {
assertEquals(detect(NoNLinput), null);
}
});
test({
name: "[EOL] Detect Mixed",
- fn() {
+ fn(): void {
assertEquals(detect(Mixedinput), EOL.CRLF);
assertEquals(detect(Mixedinput2), EOL.CRLF);
}
@@ -40,7 +40,7 @@ test({
test({
name: "[EOL] Format",
- fn() {
+ fn(): void {
assertEquals(format(CRLFinput, EOL.LF), LFinput);
assertEquals(format(LFinput, EOL.LF), LFinput);
assertEquals(format(LFinput, EOL.CRLF), CRLFinput);
diff --git a/fs/exists.ts b/fs/exists.ts
index ce4b83a4c..4638630fd 100644
--- a/fs/exists.ts
+++ b/fs/exists.ts
@@ -3,8 +3,8 @@
/** Test whether or not the given path exists by checking with the file system */
export async function exists(filePath: string): Promise<boolean> {
return Deno.lstat(filePath)
- .then(() => true)
- .catch(() => false);
+ .then((): boolean => true)
+ .catch((): boolean => false);
}
/** Test whether or not the given path exists by checking with the file system */
diff --git a/fs/exists_test.ts b/fs/exists_test.ts
index 1e94c7f69..a75cdb9f4 100644
--- a/fs/exists_test.ts
+++ b/fs/exists_test.ts
@@ -6,7 +6,7 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function existsFile() {
+test(async function existsFile(): Promise<void> {
assertEquals(
await exists(path.join(testdataDir, "not_exist_file.ts")),
false
@@ -14,12 +14,12 @@ test(async function existsFile() {
assertEquals(await existsSync(path.join(testdataDir, "0.ts")), true);
});
-test(function existsFileSync() {
+test(function existsFileSync(): void {
assertEquals(existsSync(path.join(testdataDir, "not_exist_file.ts")), false);
assertEquals(existsSync(path.join(testdataDir, "0.ts")), true);
});
-test(async function existsDirectory() {
+test(async function existsDirectory(): Promise<void> {
assertEquals(
await exists(path.join(testdataDir, "not_exist_directory")),
false
@@ -27,7 +27,7 @@ test(async function existsDirectory() {
assertEquals(existsSync(testdataDir), true);
});
-test(function existsDirectorySync() {
+test(function existsDirectorySync(): void {
assertEquals(
existsSync(path.join(testdataDir, "not_exist_directory")),
false
@@ -35,12 +35,12 @@ test(function existsDirectorySync() {
assertEquals(existsSync(testdataDir), true);
});
-test(function existsLinkSync() {
+test(function existsLinkSync(): void {
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
});
-test(async function existsLink() {
+test(async function existsLink(): Promise<void> {
// TODO(axetroy): generate link file use Deno api instead of set a link file in repository
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
});
diff --git a/fs/glob_test.ts b/fs/glob_test.ts
index fc3704ae3..5772373dd 100644
--- a/fs/glob_test.ts
+++ b/fs/glob_test.ts
@@ -20,8 +20,9 @@ async function walkArray(
arr.push(f.path.replace(/\\/g, "/"));
}
arr.sort();
- const arrSync = Array.from(walkSync(dirname, options), (f: FileInfo) =>
- f.path.replace(/\\/g, "/")
+ const arrSync = Array.from(
+ walkSync(dirname, options),
+ (f: FileInfo): string => f.path.replace(/\\/g, "/")
).sort();
assertEquals(arr, arrSync);
return arr;
@@ -29,7 +30,7 @@ async function walkArray(
test({
name: "glob: glob to regex",
- fn() {
+ fn(): void {
assertEquals(glob("unicorn.*") instanceof RegExp, true);
assertEquals(glob("unicorn.*").test("poney.ts"), false);
assertEquals(glob("unicorn.*").test("unicorn.py"), true);
@@ -69,11 +70,11 @@ test({
});
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await touch(d + "/a/x.ts");
},
- async function globInWalk() {
+ async function globInWalk(): Promise<void> {
const arr = await walkArray(".", { match: [glob("*.ts")] });
assertEquals(arr.length, 1);
assertEquals(arr[0], "./a/x.ts");
@@ -81,14 +82,14 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await mkdir(d + "/b");
await touch(d + "/a/x.ts");
await touch(d + "/b/z.ts");
await touch(d + "/b/z.js");
},
- async function globInWalkWildcardFiles() {
+ async function globInWalkWildcardFiles(): Promise<void> {
const arr = await walkArray(".", { match: [glob("*.ts")] });
assertEquals(arr.length, 2);
assertEquals(arr[0], "./a/x.ts");
@@ -97,12 +98,12 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await mkdir(d + "/a/yo");
await touch(d + "/a/yo/x.ts");
},
- async function globInWalkFolderWildcard() {
+ async function globInWalkFolderWildcard(): Promise<void> {
const arr = await walkArray(".", {
match: [
glob(join("a", "**", "*.ts"), {
@@ -117,7 +118,7 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await mkdir(d + "/a/unicorn");
await mkdir(d + "/a/deno");
@@ -126,7 +127,7 @@ testWalk(
await touch(d + "/a/deno/x.ts");
await touch(d + "/a/unicorn/x.ts");
},
- async function globInWalkFolderExtended() {
+ async function globInWalkFolderExtended(): Promise<void> {
const arr = await walkArray(".", {
match: [
glob(join("a", "+(raptor|deno)", "*.ts"), {
@@ -142,12 +143,12 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x.ts");
await touch(d + "/x.js");
await touch(d + "/b.js");
},
- async function globInWalkWildcardExtension() {
+ async function globInWalkWildcardExtension(): Promise<void> {
const arr = await walkArray(".", {
match: [glob("x.*", { flags: "g", globstar: true })]
});
diff --git a/fs/globrex_test.ts b/fs/globrex_test.ts
index 8d43b5352..34821b620 100644
--- a/fs/globrex_test.ts
+++ b/fs/globrex_test.ts
@@ -35,7 +35,7 @@ function matchSegments(t, pattern, ifUnix, ifWin, opts): GlobrexResult {
test({
name: "globrex: standard",
- fn() {
+ fn(): void {
let res = globrex("*.js");
t.equal(typeof globrex, "function", "constructor is a typeof function");
t.equal(res instanceof Object, true, "returns object");
@@ -45,7 +45,7 @@ test({
test({
name: "globrex: Standard * matching",
- fn() {
+ fn(): void {
t.equal(match("*", "foo"), true, "match everything");
t.equal(match("*", "foo", { flags: "g" }), true, "match everything");
t.equal(match("f*", "foo"), true, "match the end");
@@ -75,7 +75,7 @@ test({
test({
name: "globrex: advance * matching",
- fn() {
+ fn(): void {
t.equal(
match("*.min.js", "http://example.com/jquery.min.js", {
globstar: false
@@ -186,7 +186,7 @@ test({
test({
name: "globrex: ? match one character, no more and no less",
- fn() {
+ fn(): void {
t.equal(match("f?o", "foo", { extended: true }), true);
t.equal(match("f?o", "fooo", { extended: true }), false);
t.equal(match("f?oo", "foo", { extended: true }), false);
@@ -226,7 +226,7 @@ test({
test({
name: "globrex: [] match a character range",
- fn() {
+ fn(): void {
t.equal(match("fo[oz]", "foo", { extended: true }), true);
t.equal(match("fo[oz]", "foz", { extended: true }), true);
t.equal(match("fo[oz]", "fog", { extended: true }), false);
@@ -257,7 +257,7 @@ test({
test({
name: "globrex: [] extended character ranges",
- fn() {
+ fn(): void {
t.equal(
match("[[:alnum:]]/bar.txt", "a/bar.txt", { extended: true }),
true
@@ -315,7 +315,7 @@ test({
test({
name: "globrex: {} match a choice of different substrings",
- fn() {
+ fn(): void {
t.equal(match("foo{bar,baaz}", "foobaaz", { extended: true }), true);
t.equal(match("foo{bar,baaz}", "foobar", { extended: true }), true);
t.equal(match("foo{bar,baaz}", "foobuzz", { extended: true }), false);
@@ -363,7 +363,7 @@ test({
test({
name: "globrex: complex extended matches",
- fn() {
+ fn(): void {
t.equal(
match(
"http://?o[oz].b*z.com/{*.js,*.html}",
@@ -455,7 +455,7 @@ test({
test({
name: "globrex: standard globstar",
- fn() {
+ fn(): void {
const tester = (globstar): void => {
t.equal(
match(
@@ -490,7 +490,7 @@ test({
test({
name: "globrex: remaining chars should match themself",
- fn() {
+ fn(): void {
const tester = (globstar): void => {
const testExtStr = "\\/$^+.()=!|,.*";
t.equal(match(testExtStr, testExtStr, { extended: true }), true);
@@ -507,7 +507,7 @@ test({
test({
name: "globrex: globstar advance testing",
- fn() {
+ fn(): void {
t.equal(match("/foo/*", "/foo/bar.txt", { globstar: true }), true);
t.equal(match("/foo/**", "/foo/bar.txt", { globstar: true }), true);
t.equal(match("/foo/**", "/foo/bar/baz.txt", { globstar: true }), true);
@@ -647,7 +647,7 @@ test({
test({
name: "globrex: extended extglob ?",
- fn() {
+ fn(): void {
t.equal(match("(foo).txt", "(foo).txt", { extended: true }), true);
t.equal(match("?(foo).txt", "foo.txt", { extended: true }), true);
t.equal(match("?(foo).txt", ".txt", { extended: true }), true);
@@ -700,7 +700,7 @@ test({
test({
name: "globrex: extended extglob *",
- fn() {
+ fn(): void {
t.equal(match("*(foo).txt", "foo.txt", { extended: true }), true);
t.equal(match("*foo.txt", "bofoo.txt", { extended: true }), true);
t.equal(match("*(foo).txt", "foofoo.txt", { extended: true }), true);
@@ -737,7 +737,7 @@ test({
test({
name: "globrex: extended extglob +",
- fn() {
+ fn(): void {
t.equal(match("+(foo).txt", "foo.txt", { extended: true }), true);
t.equal(match("+foo.txt", "+foo.txt", { extended: true }), true);
t.equal(match("+(foo).txt", ".txt", { extended: true }), false);
@@ -747,7 +747,7 @@ test({
test({
name: "globrex: extended extglob @",
- fn() {
+ fn(): void {
t.equal(match("@(foo).txt", "foo.txt", { extended: true }), true);
t.equal(match("@foo.txt", "@foo.txt", { extended: true }), true);
t.equal(match("@(foo|baz)bar.txt", "foobar.txt", { extended: true }), true);
@@ -768,7 +768,7 @@ test({
test({
name: "globrex: extended extglob !",
- fn() {
+ fn(): void {
t.equal(match("!(boo).txt", "foo.txt", { extended: true }), true);
t.equal(match("!(foo|baz)bar.txt", "buzbar.txt", { extended: true }), true);
t.equal(match("!bar.txt", "!bar.txt", { extended: true }), true);
@@ -785,7 +785,7 @@ test({
test({
name: "globrex: strict",
- fn() {
+ fn(): void {
t.equal(match("foo//bar.txt", "foo/bar.txt"), true);
t.equal(match("foo///bar.txt", "foo/bar.txt"), true);
t.equal(match("foo///bar.txt", "foo/bar.txt", { strict: true }), false);
@@ -794,7 +794,7 @@ test({
test({
name: "globrex: filepath path-regex",
- fn() {
+ fn(): void {
let opts = { extended: true, filepath: true, globstar: false },
res,
pattern;
@@ -847,7 +847,7 @@ test({
test({
name: "globrex: filepath path segments",
- fn() {
+ fn(): void {
let opts = { extended: true },
win,
unix;
@@ -895,7 +895,7 @@ test({
test({
name: "globrex: stress testing",
- fn() {
+ fn(): void {
t.equal(
match("**/*/?yfile.{md,js,txt}", "foo/bar/baz/myfile.md", {
extended: true
diff --git a/fs/move_test.ts b/fs/move_test.ts
index aa49b4cca..fae951e1f 100644
--- a/fs/move_test.ts
+++ b/fs/move_test.ts
@@ -13,16 +13,18 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function moveDirectoryIfSrcNotExists() {
+test(async function moveDirectoryIfSrcNotExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_1");
const destDir = path.join(testdataDir, "move_test_dest_1");
// if src directory not exist
- await assertThrowsAsync(async () => {
- await move(srcDir, destDir);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await move(srcDir, destDir);
+ }
+ );
});
-test(async function moveDirectoryIfDestNotExists() {
+test(async function moveDirectoryIfDestNotExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_2");
const destDir = path.join(testdataDir, "move_test_dest_2");
@@ -30,7 +32,7 @@ test(async function moveDirectoryIfDestNotExists() {
// if dest directory not exist
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await move(srcDir, destDir);
throw new Error("should not throw error");
},
@@ -41,17 +43,19 @@ test(async function moveDirectoryIfDestNotExists() {
await Deno.remove(destDir);
});
-test(async function moveFileIfSrcNotExists() {
+test(async function moveFileIfSrcNotExists(): Promise<void> {
const srcFile = path.join(testdataDir, "move_test_src_3", "test.txt");
const destFile = path.join(testdataDir, "move_test_dest_3", "test.txt");
// if src directory not exist
- await assertThrowsAsync(async () => {
- await move(srcFile, destFile);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await move(srcFile, destFile);
+ }
+ );
});
-test(async function moveFileIfDestExists() {
+test(async function moveFileIfDestExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_4");
const destDir = path.join(testdataDir, "move_test_dest_4");
const srcFile = path.join(srcDir, "test.txt");
@@ -74,7 +78,7 @@ test(async function moveFileIfDestExists() {
// move it without override
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await move(srcFile, destFile);
},
Error,
@@ -83,7 +87,7 @@ test(async function moveFileIfDestExists() {
// move again with overwrite
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await move(srcFile, destFile, { overwrite: true });
throw new Error("should not throw error");
},
@@ -101,7 +105,7 @@ test(async function moveFileIfDestExists() {
]);
});
-test(async function moveDirectory() {
+test(async function moveDirectory(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_5");
const destDir = path.join(testdataDir, "move_test_dest_5");
const srcFile = path.join(srcDir, "test.txt");
@@ -126,7 +130,9 @@ test(async function moveDirectory() {
await Deno.remove(destDir, { recursive: true });
});
-test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite() {
+test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise<
+ void
+> {
const srcDir = path.join(testdataDir, "move_test_src_6");
const destDir = path.join(testdataDir, "move_test_dest_6");
const srcFile = path.join(srcDir, "test.txt");
@@ -156,14 +162,14 @@ test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite() {
await Deno.remove(destDir, { recursive: true });
});
-test(async function moveIntoSubDir() {
+test(async function moveIntoSubDir(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_7");
const destDir = path.join(srcDir, "nest");
await ensureDir(destDir);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await move(srcDir, destDir);
},
Error,
@@ -172,16 +178,18 @@ test(async function moveIntoSubDir() {
await Deno.remove(srcDir, { recursive: true });
});
-test(function moveSyncDirectoryIfSrcNotExists() {
+test(function moveSyncDirectoryIfSrcNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_1");
const destDir = path.join(testdataDir, "move_sync_test_dest_1");
// if src directory not exist
- assertThrows(() => {
- moveSync(srcDir, destDir);
- });
+ assertThrows(
+ (): void => {
+ moveSync(srcDir, destDir);
+ }
+ );
});
-test(function moveSyncDirectoryIfDestNotExists() {
+test(function moveSyncDirectoryIfDestNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_2");
const destDir = path.join(testdataDir, "move_sync_test_dest_2");
@@ -189,7 +197,7 @@ test(function moveSyncDirectoryIfDestNotExists() {
// if dest directory not exist
assertThrows(
- () => {
+ (): void => {
moveSync(srcDir, destDir);
throw new Error("should not throw error");
},
@@ -200,17 +208,19 @@ test(function moveSyncDirectoryIfDestNotExists() {
Deno.removeSync(destDir);
});
-test(function moveSyncFileIfSrcNotExists() {
+test(function moveSyncFileIfSrcNotExists(): void {
const srcFile = path.join(testdataDir, "move_sync_test_src_3", "test.txt");
const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt");
// if src directory not exist
- assertThrows(() => {
- moveSync(srcFile, destFile);
- });
+ assertThrows(
+ (): void => {
+ moveSync(srcFile, destFile);
+ }
+ );
});
-test(function moveSyncFileIfDestExists() {
+test(function moveSyncFileIfDestExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_4");
const destDir = path.join(testdataDir, "move_sync_test_dest_4");
const srcFile = path.join(srcDir, "test.txt");
@@ -232,7 +242,7 @@ test(function moveSyncFileIfDestExists() {
// move it without override
assertThrows(
- () => {
+ (): void => {
moveSync(srcFile, destFile);
},
Error,
@@ -241,7 +251,7 @@ test(function moveSyncFileIfDestExists() {
// move again with overwrite
assertThrows(
- () => {
+ (): void => {
moveSync(srcFile, destFile, { overwrite: true });
throw new Error("should not throw error");
},
@@ -257,7 +267,7 @@ test(function moveSyncFileIfDestExists() {
Deno.removeSync(destDir, { recursive: true });
});
-test(function moveSyncDirectory() {
+test(function moveSyncDirectory(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_5");
const destDir = path.join(testdataDir, "move_sync_test_dest_5");
const srcFile = path.join(srcDir, "test.txt");
@@ -280,7 +290,7 @@ test(function moveSyncDirectory() {
Deno.removeSync(destDir, { recursive: true });
});
-test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite() {
+test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_6");
const destDir = path.join(testdataDir, "move_sync_test_dest_6");
const srcFile = path.join(srcDir, "test.txt");
@@ -307,14 +317,14 @@ test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite() {
Deno.removeSync(destDir, { recursive: true });
});
-test(function moveSyncIntoSubDir() {
+test(function moveSyncIntoSubDir(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_7");
const destDir = path.join(srcDir, "nest");
ensureDirSync(destDir);
assertThrows(
- () => {
+ (): void => {
moveSync(srcDir, destDir);
},
Error,
diff --git a/fs/read_file_str_test.ts b/fs/read_file_str_test.ts
index eb529022c..d7d67d8d4 100644
--- a/fs/read_file_str_test.ts
+++ b/fs/read_file_str_test.ts
@@ -5,14 +5,14 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(function testReadFileSync() {
+test(function testReadFileSync(): void {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = readFileStrSync(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});
-test(async function testReadFile() {
+test(async function testReadFile(): Promise<void> {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = await readFileStr(jsonFile);
assert(typeof strFile === "string");
diff --git a/fs/read_json.ts b/fs/read_json.ts
index 8979c24e8..ca5928afe 100644
--- a/fs/read_json.ts
+++ b/fs/read_json.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
/** Reads a JSON file and then parses it into an object */
-export async function readJson(filePath: string): Promise<any> {
+export async function readJson(filePath: string): Promise<unknown> {
const decoder = new TextDecoder("utf-8");
const content = decoder.decode(await Deno.readFile(filePath));
@@ -15,7 +15,7 @@ export async function readJson(filePath: string): Promise<any> {
}
/** Reads a JSON file and then parses it into an object */
-export function readJsonSync(filePath: string): any {
+export function readJsonSync(filePath: string): unknown {
const decoder = new TextDecoder("utf-8");
const content = decoder.decode(Deno.readFileSync(filePath));
diff --git a/fs/read_json_test.ts b/fs/read_json_test.ts
index ca32ee053..c8aa6dcf1 100644
--- a/fs/read_json_test.ts
+++ b/fs/read_json_test.ts
@@ -10,31 +10,37 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function readJsonFileNotExists() {
+test(async function readJsonFileNotExists(): Promise<void> {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
- await assertThrowsAsync(async () => {
- await readJson(emptyJsonFile);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await readJson(emptyJsonFile);
+ }
+ );
});
-test(async function readEmptyJsonFile() {
+test(async function readEmptyJsonFile(): Promise<void> {
const emptyJsonFile = path.join(testdataDir, "json_empty.json");
- await assertThrowsAsync(async () => {
- await readJson(emptyJsonFile);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await readJson(emptyJsonFile);
+ }
+ );
});
-test(async function readInvalidJsonFile() {
+test(async function readInvalidJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
- await assertThrowsAsync(async () => {
- await readJson(invalidJsonFile);
- });
+ await assertThrowsAsync(
+ async (): Promise<void> => {
+ await readJson(invalidJsonFile);
+ }
+ );
});
-test(async function readValidArrayJsonFile() {
+test(async function readValidArrayJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = await readJson(invalidJsonFile);
@@ -42,7 +48,7 @@ test(async function readValidArrayJsonFile() {
assertEquals(json, ["1", "2", "3"]);
});
-test(async function readValidObjJsonFile() {
+test(async function readValidObjJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = await readJson(invalidJsonFile);
@@ -50,37 +56,43 @@ test(async function readValidObjJsonFile() {
assertEquals(json, { key1: "value1", key2: "value2" });
});
-test(async function readValidObjJsonFileWithRelativePath() {
+test(async function readValidObjJsonFileWithRelativePath(): Promise<void> {
const json = await readJson("./fs/testdata/json_valid_obj.json");
assertEquals(json, { key1: "value1", key2: "value2" });
});
-test(function readJsonFileNotExistsSync() {
+test(function readJsonFileNotExistsSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
- assertThrows(() => {
- readJsonSync(emptyJsonFile);
- });
+ assertThrows(
+ (): void => {
+ readJsonSync(emptyJsonFile);
+ }
+ );
});
-test(function readEmptyJsonFileSync() {
+test(function readEmptyJsonFileSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_empty.json");
- assertThrows(() => {
- readJsonSync(emptyJsonFile);
- });
+ assertThrows(
+ (): void => {
+ readJsonSync(emptyJsonFile);
+ }
+ );
});
-test(function readInvalidJsonFile() {
+test(function readInvalidJsonFile(): void {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
- assertThrows(() => {
- readJsonSync(invalidJsonFile);
- });
+ assertThrows(
+ (): void => {
+ readJsonSync(invalidJsonFile);
+ }
+ );
});
-test(function readValidArrayJsonFileSync() {
+test(function readValidArrayJsonFileSync(): void {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = readJsonSync(invalidJsonFile);
@@ -88,7 +100,7 @@ test(function readValidArrayJsonFileSync() {
assertEquals(json, ["1", "2", "3"]);
});
-test(function readValidObjJsonFileSync() {
+test(function readValidObjJsonFileSync(): void {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = readJsonSync(invalidJsonFile);
@@ -96,7 +108,7 @@ test(function readValidObjJsonFileSync() {
assertEquals(json, { key1: "value1", key2: "value2" });
});
-test(function readValidObjJsonFileSyncWithRelativePath() {
+test(function readValidObjJsonFileSyncWithRelativePath(): void {
const json = readJsonSync("./fs/testdata/json_valid_obj.json");
assertEquals(json, { key1: "value1", key2: "value2" });
diff --git a/fs/utils.ts b/fs/utils.ts
index 06b4c295c..83390ad70 100644
--- a/fs/utils.ts
+++ b/fs/utils.ts
@@ -17,7 +17,7 @@ export function isSubdir(
const srcArray = src.split(sep);
const destArray = dest.split(sep);
- return srcArray.reduce((acc: boolean, current, i) => {
+ return srcArray.reduce((acc, current, i): boolean => {
return acc && destArray[i] === current;
}, true);
}
diff --git a/fs/utils_test.ts b/fs/utils_test.ts
index d833aa559..5b33842ad 100644
--- a/fs/utils_test.ts
+++ b/fs/utils_test.ts
@@ -9,7 +9,7 @@ import { ensureDirSync } from "./ensure_dir.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(function _isSubdir() {
+test(function _isSubdir(): void {
const pairs = [
["", "", false, path.posix.sep],
["/first/second", "/first", false, path.posix.sep],
@@ -21,7 +21,7 @@ test(function _isSubdir() {
["c:\\first", "c:\\first\\second", true, path.win32.sep]
];
- pairs.forEach(function(p) {
+ pairs.forEach(function(p): void {
const src = p[0] as string;
const dest = p[1] as string;
const expected = p[2] as boolean;
@@ -34,13 +34,13 @@ test(function _isSubdir() {
});
});
-test(function _getFileInfoType() {
+test(function _getFileInfoType(): void {
const pairs = [
[path.join(testdataDir, "file_type_1"), "file"],
[path.join(testdataDir, "file_type_dir_1"), "dir"]
];
- pairs.forEach(function(p) {
+ pairs.forEach(function(p): void {
const filePath = p[0] as string;
const type = p[1] as PathType;
switch (type) {
diff --git a/fs/walk.ts b/fs/walk.ts
index 1e433e18b..b21044e72 100644
--- a/fs/walk.ts
+++ b/fs/walk.ts
@@ -14,15 +14,20 @@ function patternTest(patterns: RegExp[], path: string): boolean {
// Forced to reset last index on regex while iterating for have
// consistent results.
// See: https://stackoverflow.com/a/1520853
- return patterns.some(pattern => {
- let r = pattern.test(path);
- pattern.lastIndex = 0;
- return r;
- });
+ return patterns.some(
+ (pattern): boolean => {
+ let r = pattern.test(path);
+ pattern.lastIndex = 0;
+ return r;
+ }
+ );
}
function include(f: FileInfo, options: WalkOptions): boolean {
- if (options.exts && !options.exts.some(ext => f.path.endsWith(ext))) {
+ if (
+ options.exts &&
+ !options.exts.some((ext): boolean => f.path.endsWith(ext))
+ ) {
return false;
}
if (options.match && !patternTest(options.match, f.path)) {
diff --git a/fs/walk_test.ts b/fs/walk_test.ts
index 4c72de2c7..e94a653c6 100644
--- a/fs/walk_test.ts
+++ b/fs/walk_test.ts
@@ -35,8 +35,9 @@ async function walkArray(
arr.push(f.path.replace(/\\/g, "/"));
}
arr.sort();
- const arrSync = Array.from(walkSync(dirname, options), (f: FileInfo) =>
- f.path.replace(/\\/g, "/")
+ const arrSync = Array.from(
+ walkSync(dirname, options),
+ (f: FileInfo): string => f.path.replace(/\\/g, "/")
).sort();
assertEquals(arr, arrSync);
return arr;
@@ -46,25 +47,25 @@ async function touch(path: string): Promise<void> {
await open(path, "w");
}
function assertReady(expectedLength: number): void {
- const arr = Array.from(walkSync(), (f: FileInfo) => f.path);
+ const arr = Array.from(walkSync(), (f: FileInfo): string => f.path);
assertEquals(arr.length, expectedLength);
}
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/empty");
},
- async function emptyDir() {
+ async function emptyDir(): Promise<void> {
const arr = await walkArray();
assertEquals(arr.length, 0);
}
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
},
- async function singleFile() {
+ async function singleFile(): Promise<void> {
const arr = await walkArray();
assertEquals(arr.length, 1);
assertEquals(arr[0], "./x");
@@ -72,10 +73,10 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
},
- async function iteratable() {
+ async function iteratable(): Promise<void> {
let count = 0;
for (const _ of walkSync()) {
count += 1;
@@ -89,11 +90,11 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await touch(d + "/a/x");
},
- async function nestedSingleFile() {
+ async function nestedSingleFile(): Promise<void> {
const arr = await walkArray();
assertEquals(arr.length, 1);
assertEquals(arr[0], "./a/x");
@@ -101,11 +102,11 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a/b/c/d", true);
await touch(d + "/a/b/c/d/x");
},
- async function depth() {
+ async function depth(): Promise<void> {
assertReady(1);
const arr3 = await walkArray(".", { maxDepth: 3 });
assertEquals(arr3.length, 0);
@@ -116,11 +117,11 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x.ts");
await touch(d + "/y.rs");
},
- async function ext() {
+ async function ext(): Promise<void> {
assertReady(2);
const arr = await walkArray(".", { exts: [".ts"] });
assertEquals(arr.length, 1);
@@ -129,12 +130,12 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x.ts");
await touch(d + "/y.rs");
await touch(d + "/z.py");
},
- async function extAny() {
+ async function extAny(): Promise<void> {
assertReady(3);
const arr = await walkArray(".", { exts: [".rs", ".ts"] });
assertEquals(arr.length, 2);
@@ -144,11 +145,11 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
await touch(d + "/y");
},
- async function match() {
+ async function match(): Promise<void> {
assertReady(2);
const arr = await walkArray(".", { match: [/x/] });
assertEquals(arr.length, 1);
@@ -157,12 +158,12 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
await touch(d + "/y");
await touch(d + "/z");
},
- async function matchAny() {
+ async function matchAny(): Promise<void> {
assertReady(3);
const arr = await walkArray(".", { match: [/x/, /y/] });
assertEquals(arr.length, 2);
@@ -172,11 +173,11 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
await touch(d + "/y");
},
- async function skip() {
+ async function skip(): Promise<void> {
assertReady(2);
const arr = await walkArray(".", { skip: [/x/] });
assertEquals(arr.length, 1);
@@ -185,12 +186,12 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await touch(d + "/x");
await touch(d + "/y");
await touch(d + "/z");
},
- async function skipAny() {
+ async function skipAny(): Promise<void> {
assertReady(3);
const arr = await walkArray(".", { skip: [/x/, /y/] });
assertEquals(arr.length, 1);
@@ -199,14 +200,14 @@ testWalk(
);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await mkdir(d + "/b");
await touch(d + "/a/x");
await touch(d + "/a/y");
await touch(d + "/b/z");
},
- async function subDir() {
+ async function subDir(): Promise<void> {
assertReady(3);
const arr = await walkArray("b");
assertEquals(arr.length, 1);
@@ -214,18 +215,21 @@ testWalk(
}
);
-testWalk(async (_d: string) => {}, async function onError() {
- assertReady(0);
- const ignored = await walkArray("missing");
- assertEquals(ignored.length, 0);
- let errors = 0;
- await walkArray("missing", { onError: _e => (errors += 1) });
- // It's 2 since walkArray iterates over both sync and async.
- assertEquals(errors, 2);
-});
+testWalk(
+ async (_d: string): Promise<void> => {},
+ async function onError(): Promise<void> {
+ assertReady(0);
+ const ignored = await walkArray("missing");
+ assertEquals(ignored.length, 0);
+ let errors = 0;
+ await walkArray("missing", { onError: (_e): number => (errors += 1) });
+ // It's 2 since walkArray iterates over both sync and async.
+ assertEquals(errors, 2);
+ }
+);
testWalk(
- async (d: string) => {
+ async (d: string): Promise<void> => {
await mkdir(d + "/a");
await mkdir(d + "/b");
await touch(d + "/a/x");
@@ -238,7 +242,7 @@ testWalk(
assert(err.message, "Not implemented");
}
},
- async function symlink() {
+ async function symlink(): Promise<void> {
// symlink is not yet implemented on Windows.
if (isWindows) {
return;
@@ -251,6 +255,6 @@ testWalk(
const arr = await walkArray("a", { followSymlinks: true });
assertEquals(arr.length, 3);
- assert(arr.some(f => f.endsWith("/b/z")));
+ assert(arr.some((f): boolean => f.endsWith("/b/z")));
}
);
diff --git a/fs/write_file_str_test.ts b/fs/write_file_str_test.ts
index 4039b26f6..77b1e734e 100644
--- a/fs/write_file_str_test.ts
+++ b/fs/write_file_str_test.ts
@@ -5,7 +5,7 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(function testReadFileSync() {
+test(function testReadFileSync(): void {
const jsonFile = path.join(testdataDir, "write_file_1.json");
const content = "write_file_str_test";
writeFileStrSync(jsonFile, content);
@@ -21,7 +21,7 @@ test(function testReadFileSync() {
assertEquals(content, result);
});
-test(async function testReadFile() {
+test(async function testReadFile(): Promise<void> {
const jsonFile = path.join(testdataDir, "write_file_2.json");
const content = "write_file_str_test";
await writeFileStr(jsonFile, content);
diff --git a/fs/write_json_test.ts b/fs/write_json_test.ts
index acc366001..a282d399f 100644
--- a/fs/write_json_test.ts
+++ b/fs/write_json_test.ts
@@ -10,11 +10,11 @@ import * as path from "./path/mod.ts";
const testdataDir = path.resolve("fs", "testdata");
-test(async function writeJsonIfNotExists() {
+test(async function writeJsonIfNotExists(): Promise<void> {
const notExistsJsonFile = path.join(testdataDir, "file_not_exists.json");
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await writeJson(notExistsJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -29,13 +29,13 @@ test(async function writeJsonIfNotExists() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(async function writeJsonIfExists() {
+test(async function writeJsonIfExists(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_exists.json");
await Deno.writeFile(existsJsonFile, new Uint8Array());
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await writeJson(existsJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -50,7 +50,7 @@ test(async function writeJsonIfExists() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(async function writeJsonIfExistsAnInvalidJson() {
+test(async function writeJsonIfExistsAnInvalidJson(): Promise<void> {
const existsInvalidJsonFile = path.join(
testdataDir,
"file_write_invalid.json"
@@ -60,7 +60,7 @@ test(async function writeJsonIfExistsAnInvalidJson() {
await Deno.writeFile(existsInvalidJsonFile, invalidJsonContent);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await writeJson(existsInvalidJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -75,14 +75,14 @@ test(async function writeJsonIfExistsAnInvalidJson() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(async function writeJsonWithSpaces() {
+test(async function writeJsonWithSpaces(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_spaces.json");
const invalidJsonContent = new TextEncoder().encode();
await Deno.writeFile(existsJsonFile, invalidJsonContent);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await writeJson(existsJsonFile, { a: "1" }, { spaces: 2 });
throw new Error("should write success");
},
@@ -97,14 +97,14 @@ test(async function writeJsonWithSpaces() {
assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`);
});
-test(async function writeJsonWithReplacer() {
+test(async function writeJsonWithReplacer(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_replacer.json");
const invalidJsonContent = new TextEncoder().encode();
await Deno.writeFile(existsJsonFile, invalidJsonContent);
await assertThrowsAsync(
- async () => {
+ async (): Promise<void> => {
await writeJson(
existsJsonFile,
{ a: "1", b: "2", c: "3" },
@@ -125,11 +125,11 @@ test(async function writeJsonWithReplacer() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(function writeJsonSyncIfNotExists() {
+test(function writeJsonSyncIfNotExists(): void {
const notExistsJsonFile = path.join(testdataDir, "file_not_exists_sync.json");
assertThrows(
- () => {
+ (): void => {
writeJsonSync(notExistsJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -144,13 +144,13 @@ test(function writeJsonSyncIfNotExists() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(function writeJsonSyncIfExists() {
+test(function writeJsonSyncIfExists(): void {
const existsJsonFile = path.join(testdataDir, "file_write_exists_sync.json");
Deno.writeFileSync(existsJsonFile, new Uint8Array());
assertThrows(
- () => {
+ (): void => {
writeJsonSync(existsJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -165,7 +165,7 @@ test(function writeJsonSyncIfExists() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(function writeJsonSyncIfExistsAnInvalidJson() {
+test(function writeJsonSyncIfExistsAnInvalidJson(): void {
const existsInvalidJsonFile = path.join(
testdataDir,
"file_write_invalid_sync.json"
@@ -175,7 +175,7 @@ test(function writeJsonSyncIfExistsAnInvalidJson() {
Deno.writeFileSync(existsInvalidJsonFile, invalidJsonContent);
assertThrows(
- () => {
+ (): void => {
writeJsonSync(existsInvalidJsonFile, { a: "1" });
throw new Error("should write success");
},
@@ -190,14 +190,14 @@ test(function writeJsonSyncIfExistsAnInvalidJson() {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
-test(function writeJsonWithSpaces() {
+test(function writeJsonWithSpaces(): void {
const existsJsonFile = path.join(testdataDir, "file_write_spaces_sync.json");
const invalidJsonContent = new TextEncoder().encode();
Deno.writeFileSync(existsJsonFile, invalidJsonContent);
assertThrows(
- () => {
+ (): void => {
writeJsonSync(existsJsonFile, { a: "1" }, { spaces: 2 });
throw new Error("should write success");
},
@@ -212,7 +212,7 @@ test(function writeJsonWithSpaces() {
assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`);
});
-test(function writeJsonWithReplacer() {
+test(function writeJsonWithReplacer(): void {
const existsJsonFile = path.join(
testdataDir,
"file_write_replacer_sync.json"
@@ -222,7 +222,7 @@ test(function writeJsonWithReplacer() {
Deno.writeFileSync(existsJsonFile, invalidJsonContent);
assertThrows(
- () => {
+ (): void => {
writeJsonSync(
existsJsonFile,
{ a: "1", b: "2", c: "3" },