Skip to content

Commit

Permalink
refactor(fs): correct test names (#3835)
Browse files Browse the repository at this point in the history
* chore(fs): Update fs test descriptions

* fixes "throws" to "rejects" when appropriate

* Update fs/eol_test.ts

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
  • Loading branch information
JakeAve and iuioiua authored Nov 23, 2023
1 parent 830d387 commit bc540fb
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 139 deletions.
8 changes: 4 additions & 4 deletions fs/_util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ensureDirSync } from "./ensure_dir.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");

Deno.test("_isSubdir", function () {
Deno.test("isSubdir() returns a boolean indicating if dir is a subdir", function () {
const pairs = [
["", "", false, path.posix.sep],
["/first/second", "/first", false, path.posix.sep],
Expand All @@ -35,7 +35,7 @@ Deno.test("_isSubdir", function () {
});
});

Deno.test("_getFileInfoType", function () {
Deno.test("getFileInfoType() returns entity type as a string", function () {
const pairs = [
[path.join(testdataDir, "file_type_1"), "file"],
[path.join(testdataDir, "file_type_dir_1"), "dir"],
Expand Down Expand Up @@ -65,7 +65,7 @@ Deno.test("_getFileInfoType", function () {
});

Deno.test({
name: "_isSamePathWin32",
name: "isSamePath() works correctly for win32",
ignore: Deno.build.os !== "windows",
fn() {
const pairs: (string | URL | boolean)[][] = [
Expand All @@ -91,7 +91,7 @@ Deno.test({
});

Deno.test({
name: "_isSamePathPosix",
name: "isSamePath() works correctly for posix",
ignore: Deno.build.os === "windows",
fn() {
const pairs: (string | URL | boolean)[][] = [
Expand Down
37 changes: 18 additions & 19 deletions fs/copy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function testCopySync(name: string, cb: (tempDir: string) => void) {
}

testCopy(
"[fs] copy file if it does no exist",
"copy() rejects if src does not exist",
async (tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file_not_exists.txt");
const destFile = path.join(tempDir, "copy_file_not_exists_1.txt");
Expand All @@ -60,7 +60,7 @@ testCopy(
);

testCopy(
"[fs] copy if src and dest are the same paths",
"copy() rejects if src and dest are the same paths",
async (tempDir: string) => {
const srcFile = path.join(tempDir, "copy_file_same.txt");
const destFile = path.join(tempDir, "copy_file_same.txt");
Expand All @@ -75,7 +75,7 @@ testCopy(
);

testCopy(
"[fs] copy file",
"copy() copies file to new destination",
async (tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy.txt");
Expand Down Expand Up @@ -125,7 +125,7 @@ testCopy(
);

testCopy(
"[fs] copy with preserve timestamps",
"copy() copies with preserve timestamps",
async (tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy.txt");
Expand All @@ -151,7 +151,7 @@ testCopy(
);

testCopy(
"[fs] copy directory to its subdirectory",
"copy() rejects if destination is its own subdirectory",
async (tempDir: string) => {
const srcDir = path.join(tempDir, "parent");
const destDir = path.join(srcDir, "child");
Expand All @@ -169,7 +169,7 @@ testCopy(
);

testCopy(
"[fs] copy directory and destination exist and not a directory",
"copy() rejects when copying a directory to an existent destination that is not a directory",
async (tempDir: string) => {
const srcDir = path.join(tempDir, "parent");
const destDir = path.join(tempDir, "child.txt");
Expand All @@ -188,7 +188,7 @@ testCopy(
);

testCopy(
"[fs] copy directory",
"copy() copies a directory",
async (tempDir: string) => {
const srcDir = path.join(testdataDir, "copy_dir");
const destDir = path.join(tempDir, "copy_dir");
Expand Down Expand Up @@ -234,7 +234,7 @@ testCopy(
);

testCopy(
"[fs] copy symlink file",
"copy() copies a symlink file",
async (tempDir: string) => {
const dir = path.join(testdataDir, "copy_dir_link_file");
const srcLink = path.join(dir, "0.txt");
Expand All @@ -254,7 +254,7 @@ testCopy(
);

testCopy(
"[fs] copy symlink directory",
"copy() copies a symlink directory",
async (tempDir: string) => {
const srcDir = path.join(testdataDir, "copy_dir");
const srcLink = path.join(tempDir, "copy_dir_link");
Expand All @@ -276,7 +276,7 @@ testCopy(
);

testCopySync(
"[fs] copy file synchronously if it does not exist",
"copySync() throws if src does not exist",
(tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file_not_exists_sync.txt");
const destFile = path.join(tempDir, "copy_file_not_exists_1_sync.txt");
Expand All @@ -287,7 +287,7 @@ testCopySync(
);

testCopySync(
"[fs] copy synchronously with preserve timestamps",
"copySync() copies with preserve timestamps",
(tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy.txt");
Expand All @@ -313,7 +313,7 @@ testCopySync(
);

testCopySync(
"[fs] copy synchronously if src and dest are the same paths",
"copySync() throws if src and dest are the same paths",
() => {
const srcFile = path.join(testdataDir, "copy_file_same_sync.txt");
assertThrows(
Expand All @@ -326,7 +326,7 @@ testCopySync(
},
);

testCopySync("[fs] copy file synchronously", (tempDir: string) => {
testCopySync("copySync() copies file to new destination", (tempDir: string) => {
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy_sync.txt");

Expand Down Expand Up @@ -369,7 +369,7 @@ testCopySync("[fs] copy file synchronously", (tempDir: string) => {
});

testCopySync(
"[fs] copy directory synchronously to its subdirectory",
"copySync() throws if destination is its own subdirectory",
(tempDir: string) => {
const srcDir = path.join(tempDir, "parent");
const destDir = path.join(srcDir, "child");
Expand All @@ -387,8 +387,7 @@ testCopySync(
);

testCopySync(
"[fs] copy directory synchronously, and destination exist and not a " +
"directory",
"copySync() throws when copying a directory to an existent destination that is not a directory",
(tempDir: string) => {
const srcDir = path.join(tempDir, "parent_sync");
const destDir = path.join(tempDir, "child.txt");
Expand All @@ -406,7 +405,7 @@ testCopySync(
},
);

testCopySync("[fs] copy directory synchronously", (tempDir: string) => {
testCopySync("copySync() copies a directory", (tempDir: string) => {
const srcDir = path.join(testdataDir, "copy_dir");
const destDir = path.join(tempDir, "copy_dir_copy_sync");
const srcFile = path.join(srcDir, "0.txt");
Expand Down Expand Up @@ -456,7 +455,7 @@ testCopySync("[fs] copy directory synchronously", (tempDir: string) => {
});

testCopySync(
"[fs] copy symlink file synchronously",
"copySync() copies symlink file",
(tempDir: string) => {
const dir = path.join(testdataDir, "copy_dir_link_file");
const srcLink = path.join(dir, "0.txt");
Expand All @@ -476,7 +475,7 @@ testCopySync(
);

testCopySync(
"[fs] copy symlink directory synchronously",
"copySync() copies symlink directory",
(tempDir: string) => {
const originDir = path.join(testdataDir, "copy_dir");
const srcLink = path.join(tempDir, "copy_dir_link");
Expand Down
14 changes: 7 additions & 7 deletions fs/empty_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { emptyDir, emptyDirSync } from "./empty_dir.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");

Deno.test("emptyDirIfItNotExist", async function () {
Deno.test("emptyDir() creates a new dir if it does not exist", async function () {
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
Expand All @@ -27,7 +27,7 @@ Deno.test("emptyDirIfItNotExist", async function () {
}
});

Deno.test("emptyDirSyncIfItNotExist", function () {
Deno.test("emptyDirSync() creates a new dir if it does not exist", function () {
const testDir = path.join(testdataDir, "empty_dir_test_2");
const testNestDir = path.join(testDir, "nest");
// empty a dir which does not exist, then it will a create new one.
Expand All @@ -43,7 +43,7 @@ Deno.test("emptyDirSyncIfItNotExist", function () {
}
});

Deno.test("emptyDirIfItExist", async function () {
Deno.test("emptyDir() empties nested dirs and files", async function () {
const testDir = path.join(testdataDir, "empty_dir_test_3");
const testNestDir = path.join(testDir, "nest");
// create test dir
Expand Down Expand Up @@ -86,7 +86,7 @@ Deno.test("emptyDirIfItExist", async function () {
}
});

Deno.test("emptyDirSyncIfItExist", function () {
Deno.test("emptyDirSync() empties nested dirs and files", function () {
const testDir = path.join(testdataDir, "empty_dir_test_4");
const testNestDir = path.join(testDir, "nest");
// create test dir
Expand Down Expand Up @@ -186,10 +186,10 @@ const scenes: Scenes[] = [
},
];
for (const s of scenes) {
let title = `test ${s.async ? "emptyDir" : "emptyDirSync"}`;
title += `("testdata/testfolder") ${s.read ? "with" : "without"}`;
let title = `${s.async ? "emptyDir()" : "emptyDirSync()"}`;
title += ` test ("testdata/testfolder") ${s.read ? "with" : "without"}`;
title += ` --allow-read & ${s.write ? "with" : "without"} --allow-write`;
Deno.test(`[fs] emptyDirPermission ${title}`, async function (): Promise<
Deno.test(`${title} permission`, async function (): Promise<
void
> {
const testfolder = path.join(testdataDir, "testfolder");
Expand Down
16 changes: 8 additions & 8 deletions fs/ensure_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ensureFile, ensureFileSync } from "./ensure_file.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");

Deno.test("ensureDirIfItNotExist", async function () {
Deno.test("ensureDir() creates dir if it does not exist", async function () {
const baseDir = path.join(testdataDir, "ensure_dir_not_exist");
const testDir = path.join(baseDir, "test");

Expand All @@ -21,7 +21,7 @@ Deno.test("ensureDirIfItNotExist", async function () {
}
});

Deno.test("ensureDirSyncIfItNotExist", function () {
Deno.test("ensureDirSync() creates dir if it does not exist", function () {
const baseDir = path.join(testdataDir, "ensure_dir_sync_not_exist");
const testDir = path.join(baseDir, "test");

Expand All @@ -35,7 +35,7 @@ Deno.test("ensureDirSyncIfItNotExist", function () {
}
});

Deno.test("ensureDirIfItExist", async function () {
Deno.test("ensureDir() ensures existing dir exists", async function () {
const baseDir = path.join(testdataDir, "ensure_dir_exist");
const testDir = path.join(baseDir, "test");

Expand All @@ -52,7 +52,7 @@ Deno.test("ensureDirIfItExist", async function () {
}
});

Deno.test("ensureDirSyncIfItExist", function () {
Deno.test("ensureDirSync() ensures existing dir exists", function () {
const baseDir = path.join(testdataDir, "ensure_dir_sync_exist");
const testDir = path.join(baseDir, "test");

Expand All @@ -69,7 +69,7 @@ Deno.test("ensureDirSyncIfItExist", function () {
}
});

Deno.test("ensureDirIfItAsFile", async function () {
Deno.test("ensureDir() rejects if input is a file", async function () {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file");
const testFile = path.join(baseDir, "test");

Expand All @@ -88,7 +88,7 @@ Deno.test("ensureDirIfItAsFile", async function () {
}
});

Deno.test("ensureDirSyncIfItAsFile", function () {
Deno.test("ensureDirSync() throws if input is a file", function () {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file_async");
const testFile = path.join(baseDir, "test");

Expand All @@ -108,7 +108,7 @@ Deno.test("ensureDirSyncIfItAsFile", function () {
});

Deno.test({
name: "ensureDirShouldNotSwallowErrors",
name: "ensureDir() rejects permission fs write error",
permissions: { read: true },
async fn() {
const baseDir = path.join(testdataDir, "ensure_dir_without_permission");
Expand All @@ -123,7 +123,7 @@ Deno.test({
});

Deno.test({
name: "ensureDirSyncShouldNotSwallowErrors",
name: "ensureDirSync() throws permission fs write error",
permissions: { read: true },
fn() {
const baseDir = path.join(
Expand Down
16 changes: 8 additions & 8 deletions fs/ensure_file_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ensureFile, ensureFileSync } from "./ensure_file.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");

Deno.test("ensureFileIfItNotExist", async function () {
Deno.test("ensureFile() creates file if it does not exist", async function () {
const testDir = path.join(testdataDir, "ensure_file_1");
const testFile = path.join(testDir, "test.txt");

Expand All @@ -20,7 +20,7 @@ Deno.test("ensureFileIfItNotExist", async function () {
}
});

Deno.test("ensureFileSyncIfItNotExist", function () {
Deno.test("ensureFileSync() creates file if it does not exist", function () {
const testDir = path.join(testdataDir, "ensure_file_2");
const testFile = path.join(testDir, "test.txt");

Expand All @@ -34,7 +34,7 @@ Deno.test("ensureFileSyncIfItNotExist", function () {
}
});

Deno.test("ensureFileIfItExist", async function () {
Deno.test("ensureFile() ensures existing file exists", async function () {
const testDir = path.join(testdataDir, "ensure_file_3");
const testFile = path.join(testDir, "test.txt");

Expand All @@ -51,7 +51,7 @@ Deno.test("ensureFileIfItExist", async function () {
}
});

Deno.test("ensureFileSyncIfItExist", function () {
Deno.test("ensureFileSync() ensures existing file exists", function () {
const testDir = path.join(testdataDir, "ensure_file_4");
const testFile = path.join(testDir, "test.txt");

Expand All @@ -68,7 +68,7 @@ Deno.test("ensureFileSyncIfItExist", function () {
}
});

Deno.test("ensureFileIfItExistAsDir", async function () {
Deno.test("ensureFile() rejects if input is dir", async function () {
const testDir = path.join(testdataDir, "ensure_file_5");

try {
Expand All @@ -86,7 +86,7 @@ Deno.test("ensureFileIfItExistAsDir", async function () {
}
});

Deno.test("ensureFileSyncIfItExistAsDir", function () {
Deno.test("ensureFileSync() throws if input is dir", function () {
const testDir = path.join(testdataDir, "ensure_file_6");

try {
Expand All @@ -105,7 +105,7 @@ Deno.test("ensureFileSyncIfItExistAsDir", function () {
});

Deno.test({
name: "ensureFileShouldNotSwallowErrors",
name: "ensureFile() rejects permission fs write error",
permissions: { read: true },
async fn() {
const testDir = path.join(testdataDir, "ensure_file_7");
Expand All @@ -121,7 +121,7 @@ Deno.test({
});

Deno.test({
name: "ensureFileSyncShouldNotSwallowErrors",
name: "ensureFileSync() throws permission fs write error",
permissions: { read: true },
fn() {
const testDir = path.join(testdataDir, "ensure_file_8");
Expand Down
Loading

0 comments on commit bc540fb

Please sign in to comment.