summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/copy_test.ts170
-rw-r--r--fs/empty_dir_test.ts16
-rw-r--r--fs/ensure_dir_test.ts26
-rw-r--r--fs/ensure_file_test.ts36
-rw-r--r--fs/ensure_link_test.ts8
-rw-r--r--fs/ensure_symlink_test.ts26
-rw-r--r--fs/move_test.ts16
-rw-r--r--fs/read_json_test.ts24
-rw-r--r--fs/walk.ts12
9 files changed, 144 insertions, 190 deletions
diff --git a/fs/copy_test.ts b/fs/copy_test.ts
index a11838c4b..347d2532c 100644
--- a/fs/copy_test.ts
+++ b/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/fs/empty_dir_test.ts b/fs/empty_dir_test.ts
index b44e600d7..80d3a1789 100644
--- a/fs/empty_dir_test.ts
+++ b/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/fs/ensure_dir_test.ts b/fs/ensure_dir_test.ts
index ad34336dc..affffdbe6 100644
--- a/fs/ensure_dir_test.ts
+++ b/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/fs/ensure_file_test.ts b/fs/ensure_file_test.ts
index fa27133ab..56f180786 100644
--- a/fs/ensure_file_test.ts
+++ b/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/fs/ensure_link_test.ts b/fs/ensure_link_test.ts
index 593df5702..6d5758268 100644
--- a/fs/ensure_link_test.ts
+++ b/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/fs/ensure_symlink_test.ts b/fs/ensure_symlink_test.ts
index 4dee56788..82312b758 100644
--- a/fs/ensure_symlink_test.ts
+++ b/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/fs/move_test.ts b/fs/move_test.ts
index fae951e1f..bc73784b2 100644
--- a/fs/move_test.ts
+++ b/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/fs/read_json_test.ts b/fs/read_json_test.ts
index c8aa6dcf1..28f733055 100644
--- a/fs/read_json_test.ts
+++ b/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/fs/walk.ts b/fs/walk.ts
index 4520fe174..cce3bad64 100644
--- a/fs/walk.ts
+++ b/fs/walk.ts
@@ -19,13 +19,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 => {
- 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(filename: string, options: WalkOptions): boolean {