summaryrefslogtreecommitdiff
path: root/std/fs
diff options
context:
space:
mode:
Diffstat (limited to 'std/fs')
-rw-r--r--std/fs/copy_test.ts170
-rw-r--r--std/fs/empty_dir_test.ts16
-rw-r--r--std/fs/ensure_dir_test.ts26
-rw-r--r--std/fs/ensure_file_test.ts36
-rw-r--r--std/fs/ensure_link_test.ts8
-rw-r--r--std/fs/ensure_symlink_test.ts26
-rw-r--r--std/fs/expand_glob.ts8
-rw-r--r--std/fs/move_test.ts16
-rw-r--r--std/fs/read_json_test.ts24
-rw-r--r--std/fs/walk.ts12
10 files changed, 148 insertions, 194 deletions
diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts
index 46b3418ac..da84e252c 100644
--- a/std/fs/copy_test.ts
+++ b/std/fs/copy_test.ts
@@ -317,11 +317,9 @@ testCopySync(
(tempDir: string): void => {
const srcFile = path.join(testdataDir, "copy_file_not_exists_sync.txt");
const destFile = path.join(tempDir, "copy_file_not_exists_1_sync.txt");
- assertThrows(
- (): void => {
- copySync(srcFile, destFile);
- }
- );
+ assertThrows((): void => {
+ copySync(srcFile, destFile);
+ });
}
);
@@ -367,50 +365,47 @@ testCopySync(
}
);
-testCopySync(
- "[fs] copy file synchronously",
- (tempDir: string): void => {
- const srcFile = path.join(testdataDir, "copy_file.txt");
- const destFile = path.join(tempDir, "copy_file_copy_sync.txt");
+testCopySync("[fs] copy file synchronously", (tempDir: string): void => {
+ const srcFile = path.join(testdataDir, "copy_file.txt");
+ const destFile = path.join(tempDir, "copy_file_copy_sync.txt");
- const srcContent = new TextDecoder().decode(Deno.readFileSync(srcFile));
+ const srcContent = new TextDecoder().decode(Deno.readFileSync(srcFile));
- assertEquals(existsSync(srcFile), true);
- assertEquals(existsSync(destFile), false);
+ assertEquals(existsSync(srcFile), true);
+ assertEquals(existsSync(destFile), false);
- copySync(srcFile, destFile);
+ copySync(srcFile, destFile);
- assertEquals(existsSync(srcFile), true);
- assertEquals(existsSync(destFile), true);
+ assertEquals(existsSync(srcFile), true);
+ assertEquals(existsSync(destFile), true);
- const destContent = new TextDecoder().decode(Deno.readFileSync(destFile));
+ const destContent = new TextDecoder().decode(Deno.readFileSync(destFile));
- assertEquals(srcContent, destContent);
+ assertEquals(srcContent, destContent);
- // Copy again without overwrite option and it should throw an error.
- assertThrows(
- (): void => {
- copySync(srcFile, destFile);
- },
- Error,
- `'${destFile}' already exists.`
- );
+ // Copy again without overwrite option and it should throw an error.
+ assertThrows(
+ (): void => {
+ copySync(srcFile, destFile);
+ },
+ Error,
+ `'${destFile}' already exists.`
+ );
- // Modify destination file.
- Deno.writeFileSync(destFile, new TextEncoder().encode("txt copy"));
+ // Modify destination file.
+ Deno.writeFileSync(destFile, new TextEncoder().encode("txt copy"));
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destFile)),
- "txt copy"
- );
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destFile)),
+ "txt copy"
+ );
- // Copy again with overwrite option.
- copySync(srcFile, destFile, { overwrite: true });
+ // Copy again with overwrite option.
+ copySync(srcFile, destFile, { overwrite: true });
- // Make sure the file has been overwritten.
- assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt");
- }
-);
+ // Make sure the file has been overwritten.
+ assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt");
+});
testCopySync(
"[fs] copy directory synchronously to its subdirectory",
@@ -450,57 +445,54 @@ testCopySync(
}
);
-testCopySync(
- "[fs] copy directory synchronously",
- (tempDir: string): void => {
- const srcDir = path.join(testdataDir, "copy_dir");
- const destDir = path.join(tempDir, "copy_dir_copy_sync");
- const srcFile = path.join(srcDir, "0.txt");
- const destFile = path.join(destDir, "0.txt");
- const srcNestFile = path.join(srcDir, "nest", "0.txt");
- const destNestFile = path.join(destDir, "nest", "0.txt");
-
- copySync(srcDir, destDir);
-
- assertEquals(existsSync(destFile), true);
- assertEquals(existsSync(destNestFile), true);
-
- // After copy. The source and destination should have the same content.
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(srcFile)),
- new TextDecoder().decode(Deno.readFileSync(destFile))
- );
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(srcNestFile)),
- new TextDecoder().decode(Deno.readFileSync(destNestFile))
- );
-
- // Copy again without overwrite option and it should throw an error.
- assertThrows(
- (): void => {
- copySync(srcDir, destDir);
- },
- Error,
- `'${destDir}' already exists.`
- );
-
- // Modify the file in the destination directory.
- Deno.writeFileSync(destNestFile, new TextEncoder().encode("nest copy"));
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destNestFile)),
- "nest copy"
- );
-
- // Copy again with overwrite option.
- copySync(srcDir, destDir, { overwrite: true });
-
- // Make sure the file has been overwritten.
- assertEquals(
- new TextDecoder().decode(Deno.readFileSync(destNestFile)),
- "nest"
- );
- }
-);
+testCopySync("[fs] copy directory synchronously", (tempDir: string): void => {
+ const srcDir = path.join(testdataDir, "copy_dir");
+ const destDir = path.join(tempDir, "copy_dir_copy_sync");
+ const srcFile = path.join(srcDir, "0.txt");
+ const destFile = path.join(destDir, "0.txt");
+ const srcNestFile = path.join(srcDir, "nest", "0.txt");
+ const destNestFile = path.join(destDir, "nest", "0.txt");
+
+ copySync(srcDir, destDir);
+
+ assertEquals(existsSync(destFile), true);
+ assertEquals(existsSync(destNestFile), true);
+
+ // After copy. The source and destination should have the same content.
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(srcFile)),
+ new TextDecoder().decode(Deno.readFileSync(destFile))
+ );
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(srcNestFile)),
+ new TextDecoder().decode(Deno.readFileSync(destNestFile))
+ );
+
+ // Copy again without overwrite option and it should throw an error.
+ assertThrows(
+ (): void => {
+ copySync(srcDir, destDir);
+ },
+ Error,
+ `'${destDir}' already exists.`
+ );
+
+ // Modify the file in the destination directory.
+ Deno.writeFileSync(destNestFile, new TextEncoder().encode("nest copy"));
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destNestFile)),
+ "nest copy"
+ );
+
+ // Copy again with overwrite option.
+ copySync(srcDir, destDir, { overwrite: true });
+
+ // Make sure the file has been overwritten.
+ assertEquals(
+ new TextDecoder().decode(Deno.readFileSync(destNestFile)),
+ "nest"
+ );
+});
testCopySync(
"[fs] copy symlink file synchronously",
diff --git a/std/fs/empty_dir_test.ts b/std/fs/empty_dir_test.ts
index 26e751c74..ac5b13476 100644
--- a/std/fs/empty_dir_test.ts
+++ b/std/fs/empty_dir_test.ts
@@ -110,18 +110,14 @@ test(function emptyDirSyncIfItExist(): void {
assertEquals(stat.isDirectory(), true);
// nest directory have been remove
- assertThrows(
- (): void => {
- Deno.statSync(testNestDir);
- }
- );
+ assertThrows((): void => {
+ Deno.statSync(testNestDir);
+ });
// test file have been remove
- assertThrows(
- (): void => {
- Deno.statSync(testDirFile);
- }
- );
+ assertThrows((): void => {
+ Deno.statSync(testDirFile);
+ });
} finally {
// remote test dir
Deno.removeSync(testDir, { recursive: true });
diff --git a/std/fs/ensure_dir_test.ts b/std/fs/ensure_dir_test.ts
index 068ec8693..c0a06749b 100644
--- a/std/fs/ensure_dir_test.ts
+++ b/std/fs/ensure_dir_test.ts
@@ -15,11 +15,9 @@ test(async function ensureDirIfItNotExist(): Promise<void> {
await assertThrowsAsync(
async (): Promise<void> => {
- await Deno.stat(testDir).then(
- (): void => {
- throw new Error("test dir should exists.");
- }
- );
+ await Deno.stat(testDir).then((): void => {
+ throw new Error("test dir should exists.");
+ });
}
);
@@ -48,11 +46,9 @@ test(async function ensureDirIfItExist(): Promise<void> {
await assertThrowsAsync(
async (): Promise<void> => {
- await Deno.stat(testDir).then(
- (): void => {
- throw new Error("test dir should still exists.");
- }
- );
+ await Deno.stat(testDir).then((): void => {
+ throw new Error("test dir should still exists.");
+ });
}
);
@@ -68,12 +64,10 @@ test(function ensureDirSyncIfItExist(): void {
ensureDirSync(testDir);
- assertThrows(
- (): void => {
- 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 });
});
diff --git a/std/fs/ensure_file_test.ts b/std/fs/ensure_file_test.ts
index bb23084a8..efd88d983 100644
--- a/std/fs/ensure_file_test.ts
+++ b/std/fs/ensure_file_test.ts
@@ -14,11 +14,9 @@ test(async function ensureFileIfItNotExist(): Promise<void> {
await assertThrowsAsync(
async (): Promise<void> => {
- await Deno.stat(testFile).then(
- (): void => {
- throw new Error("test file should exists.");
- }
- );
+ await Deno.stat(testFile).then((): void => {
+ throw new Error("test file should exists.");
+ });
}
);
@@ -31,12 +29,10 @@ test(function ensureFileSyncIfItNotExist(): void {
ensureFileSync(testFile);
- assertThrows(
- (): void => {
- 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 });
});
@@ -52,11 +48,9 @@ test(async function ensureFileIfItExist(): Promise<void> {
await assertThrowsAsync(
async (): Promise<void> => {
- await Deno.stat(testFile).then(
- (): void => {
- throw new Error("test file should exists.");
- }
- );
+ await Deno.stat(testFile).then((): void => {
+ throw new Error("test file should exists.");
+ });
}
);
@@ -72,12 +66,10 @@ test(function ensureFileSyncIfItExist(): void {
ensureFileSync(testFile);
- assertThrows(
- (): void => {
- 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 });
});
diff --git a/std/fs/ensure_link_test.ts b/std/fs/ensure_link_test.ts
index 044f80f8d..d15e5c1f6 100644
--- a/std/fs/ensure_link_test.ts
+++ b/std/fs/ensure_link_test.ts
@@ -31,11 +31,9 @@ test(function ensureLinkSyncIfItNotExist(): void {
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
- assertThrows(
- (): void => {
- ensureLinkSync(testFile, linkFile);
- }
- );
+ assertThrows((): void => {
+ ensureLinkSync(testFile, linkFile);
+ });
Deno.removeSync(testDir, { recursive: true });
});
diff --git a/std/fs/ensure_symlink_test.ts b/std/fs/ensure_symlink_test.ts
index 0c2c53e5d..6c1fe5fb5 100644
--- a/std/fs/ensure_symlink_test.ts
+++ b/std/fs/ensure_symlink_test.ts
@@ -24,11 +24,9 @@ test(async function ensureSymlinkIfItNotExist(): Promise<void> {
assertThrowsAsync(
async (): Promise<void> => {
- await Deno.stat(testFile).then(
- (): void => {
- throw new Error("test file should exists.");
- }
- );
+ await Deno.stat(testFile).then((): void => {
+ throw new Error("test file should exists.");
+ });
}
);
});
@@ -37,18 +35,14 @@ test(function ensureSymlinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "link_file_2");
const testFile = path.join(testDir, "test.txt");
- assertThrows(
- (): void => {
- ensureSymlinkSync(testFile, path.join(testDir, "test1.txt"));
- }
- );
+ assertThrows((): void => {
+ ensureSymlinkSync(testFile, path.join(testDir, "test1.txt"));
+ });
- assertThrows(
- (): void => {
- 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(): Promise<void> {
diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts
index c43e09d40..8965773a7 100644
--- a/std/fs/expand_glob.ts
+++ b/std/fs/expand_glob.ts
@@ -136,8 +136,8 @@ export async function* expandGlob(
);
}
if (hasTrailingSep) {
- currentMatches = currentMatches.filter(
- ({ info }): boolean => info.isDirectory()
+ currentMatches = currentMatches.filter(({ info }): boolean =>
+ info.isDirectory()
);
}
if (!includeDirs) {
@@ -238,8 +238,8 @@ export function* expandGlobSync(
);
}
if (hasTrailingSep) {
- currentMatches = currentMatches.filter(
- ({ info }): boolean => info.isDirectory()
+ currentMatches = currentMatches.filter(({ info }): boolean =>
+ info.isDirectory()
);
}
if (!includeDirs) {
diff --git a/std/fs/move_test.ts b/std/fs/move_test.ts
index fc0141d8e..d45ae1cf5 100644
--- a/std/fs/move_test.ts
+++ b/std/fs/move_test.ts
@@ -182,11 +182,9 @@ 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(
- (): void => {
- moveSync(srcDir, destDir);
- }
- );
+ assertThrows((): void => {
+ moveSync(srcDir, destDir);
+ });
});
test(function moveSyncDirectoryIfDestNotExists(): void {
@@ -213,11 +211,9 @@ test(function moveSyncFileIfSrcNotExists(): void {
const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt");
// if src directory not exist
- assertThrows(
- (): void => {
- moveSync(srcFile, destFile);
- }
- );
+ assertThrows((): void => {
+ moveSync(srcFile, destFile);
+ });
});
test(function moveSyncFileIfDestExists(): void {
diff --git a/std/fs/read_json_test.ts b/std/fs/read_json_test.ts
index a9362b0ac..c4c8d67d8 100644
--- a/std/fs/read_json_test.ts
+++ b/std/fs/read_json_test.ts
@@ -65,31 +65,25 @@ test(async function readValidObjJsonFileWithRelativePath(): Promise<void> {
test(function readJsonFileNotExistsSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
- assertThrows(
- (): void => {
- readJsonSync(emptyJsonFile);
- }
- );
+ assertThrows((): void => {
+ readJsonSync(emptyJsonFile);
+ });
});
test(function readEmptyJsonFileSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_empty.json");
- assertThrows(
- (): void => {
- readJsonSync(emptyJsonFile);
- }
- );
+ assertThrows((): void => {
+ readJsonSync(emptyJsonFile);
+ });
});
test(function readInvalidJsonFile(): void {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
- assertThrows(
- (): void => {
- readJsonSync(invalidJsonFile);
- }
- );
+ assertThrows((): void => {
+ readJsonSync(invalidJsonFile);
+ });
});
test(function readValidArrayJsonFileSync(): void {
diff --git a/std/fs/walk.ts b/std/fs/walk.ts
index efc54bc23..60eb9b483 100644
--- a/std/fs/walk.ts
+++ b/std/fs/walk.ts
@@ -21,13 +21,11 @@ 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): boolean => {
- const r = pattern.test(path);
- pattern.lastIndex = 0;
- return r;
- }
- );
+ return patterns.some((pattern): boolean => {
+ const r = pattern.test(path);
+ pattern.lastIndex = 0;
+ return r;
+ });
}
function include(filename: string, options: WalkOptions): boolean {