diff --git a/fs/_util_test.ts b/fs/_util_test.ts index 39e8cafd68f3..a2b2cadfad42 100644 --- a/fs/_util_test.ts +++ b/fs/_util_test.ts @@ -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], @@ -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"], @@ -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)[][] = [ @@ -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)[][] = [ diff --git a/fs/copy_test.ts b/fs/copy_test.ts index fa6699bcf5e4..7b135cbabf98 100644 --- a/fs/copy_test.ts +++ b/fs/copy_test.ts @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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( @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); diff --git a/fs/empty_dir_test.ts b/fs/empty_dir_test.ts index 54cdfa7e2089..a328cc555000 100644 --- a/fs/empty_dir_test.ts +++ b/fs/empty_dir_test.ts @@ -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 @@ -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. @@ -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 @@ -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 @@ -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"); diff --git a/fs/ensure_dir_test.ts b/fs/ensure_dir_test.ts index 5750da10fa2a..fe71bf1e2933 100644 --- a/fs/ensure_dir_test.ts +++ b/fs/ensure_dir_test.ts @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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( diff --git a/fs/ensure_file_test.ts b/fs/ensure_file_test.ts index 0a06daa97548..69ad3c67de87 100644 --- a/fs/ensure_file_test.ts +++ b/fs/ensure_file_test.ts @@ -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"); @@ -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"); @@ -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"); @@ -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"); @@ -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 { @@ -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 { @@ -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"); @@ -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"); diff --git a/fs/ensure_link_test.ts b/fs/ensure_link_test.ts index aaeb60ddcc11..5b97ea7f3077 100644 --- a/fs/ensure_link_test.ts +++ b/fs/ensure_link_test.ts @@ -7,7 +7,7 @@ import { ensureLink, ensureLinkSync } from "./ensure_link.ts"; const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); const testdataDir = path.resolve(moduleDir, "testdata"); -Deno.test("ensureLinkIfItNotExist", async function () { +Deno.test("ensureLink() rejects if src and dest do not exist", async function () { const srcDir = path.join(testdataDir, "ensure_link_1"); const destDir = path.join(testdataDir, "ensure_link_1_2"); const testFile = path.join(srcDir, "test.txt"); @@ -22,7 +22,7 @@ Deno.test("ensureLinkIfItNotExist", async function () { await Deno.remove(destDir, { recursive: true }); }); -Deno.test("ensureLinkSyncIfItNotExist", function () { +Deno.test("ensureLinkSync() throws if src and dest do not exist", function () { const testDir = path.join(testdataDir, "ensure_link_2"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -34,7 +34,7 @@ Deno.test("ensureLinkSyncIfItNotExist", function () { Deno.removeSync(testDir, { recursive: true }); }); -Deno.test("ensureLinkIfItExist", async function () { +Deno.test("ensureLink() ensures dest links to the src", async function () { const testDir = path.join(testdataDir, "ensure_link_3"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -73,7 +73,7 @@ Deno.test("ensureLinkIfItExist", async function () { await Deno.remove(testDir, { recursive: true }); }); -Deno.test("ensureLinkSyncIfItExist", function () { +Deno.test("ensureLinkSync() ensures dest links to the src", function () { const testDir = path.join(testdataDir, "ensure_link_4"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -121,7 +121,7 @@ Deno.test("ensureLinkSyncIfItExist", function () { Deno.removeSync(testDir, { recursive: true }); }); -Deno.test("ensureLinkDirectoryIfItExist", async function () { +Deno.test("ensureLink() rejects if link does not exist", async function () { 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 +140,7 @@ Deno.test("ensureLinkDirectoryIfItExist", async function () { Deno.removeSync(testDir, { recursive: true }); }); -Deno.test("ensureLinkSyncDirectoryIfItExist", function () { +Deno.test("ensureLinkSync() throws if link does not exist", function () { 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"); diff --git a/fs/ensure_symlink_test.ts b/fs/ensure_symlink_test.ts index f7b86a4b0689..6c650bffb601 100644 --- a/fs/ensure_symlink_test.ts +++ b/fs/ensure_symlink_test.ts @@ -7,7 +7,7 @@ import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts"; const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); const testdataDir = path.resolve(moduleDir, "testdata"); -Deno.test("ensureSymlinkIfItNotExist", async function () { +Deno.test("ensureSymlink() rejects if file does not exist", async function () { const testDir = path.join(testdataDir, "link_file_1"); const testFile = path.join(testDir, "test.txt"); @@ -20,13 +20,13 @@ Deno.test("ensureSymlinkIfItNotExist", async function () { await assertRejects( async () => { await Deno.stat(testFile).then(() => { - throw new Error("test file should exists."); + throw new Error("test file should exist."); }); }, ); }); -Deno.test("ensureSymlinkSyncIfItNotExist", function () { +Deno.test("ensureSymlinkSync() throws if file does not exist", function () { const testDir = path.join(testdataDir, "link_file_2"); const testFile = path.join(testDir, "test.txt"); @@ -36,11 +36,11 @@ Deno.test("ensureSymlinkSyncIfItNotExist", function () { assertThrows(() => { Deno.statSync(testFile); - throw new Error("test file should exists."); + throw new Error("test file should exist."); }); }); -Deno.test("ensureSymlinkIfItExist", async function () { +Deno.test("ensureSymlink() ensures linkName links to target", async function () { const testDir = path.join(testdataDir, "link_file_3"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -60,7 +60,7 @@ Deno.test("ensureSymlinkIfItExist", async function () { await Deno.remove(testDir, { recursive: true }); }); -Deno.test("ensureSymlinkSyncIfItExist", function () { +Deno.test("ensureSymlinkSync() ensures linkName links to target", function () { const testDir = path.join(testdataDir, "link_file_4"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -80,7 +80,7 @@ Deno.test("ensureSymlinkSyncIfItExist", function () { Deno.removeSync(testDir, { recursive: true }); }); -Deno.test("ensureSymlinkDirectoryIfItExist", async function () { +Deno.test("ensureSymlink() ensures dir linkName links to dir target", async function () { 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"); @@ -103,7 +103,7 @@ Deno.test("ensureSymlinkDirectoryIfItExist", async function () { await Deno.remove(testDir, { recursive: true }); }); -Deno.test("ensureSymlinkSyncDirectoryIfItExist", function () { +Deno.test("ensureSymlinkSync() ensures dir linkName links to dir target", function () { 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"); @@ -126,7 +126,7 @@ Deno.test("ensureSymlinkSyncDirectoryIfItExist", function () { Deno.removeSync(testDir, { recursive: true }); }); -Deno.test("ensureSymlinkRelativeTarget", async function () { +Deno.test("ensureSymlink() creates symlink with relative target", async function () { const testDir = path.join(testdataDir, "symlink-relative"); const testLinkName = path.join(testDir, "link.txt"); const testFile = path.join(testDir, "target.txt"); @@ -148,7 +148,7 @@ Deno.test("ensureSymlinkRelativeTarget", async function () { await Deno.remove(testDir, { recursive: true }); }); -Deno.test("ensureSymlinkSyncRelativeTarget", function () { +Deno.test("ensureSymlinkSync() creates symlink with relative target", function () { const testDir = path.join(testdataDir, "symlink-relative-sync"); const testLinkName = path.join(testDir, "link.txt"); const testFile = path.join(testDir, "target.txt"); diff --git a/fs/eol_test.ts b/fs/eol_test.ts index 9807b038bef9..0cb918e590d5 100644 --- a/fs/eol_test.ts +++ b/fs/eol_test.ts @@ -9,28 +9,29 @@ const LFinput = "deno\nis not\nnode"; const NoNLinput = "deno is not node"; Deno.test({ - name: "[EOL] Detect CR LF", + name: "detect() detects CRLF as the end-of-line character", fn() { assertEquals(detect(CRLFinput), EOL.CRLF); }, }); Deno.test({ - name: "[EOL] Detect LF", + name: "detect() detects LF as the end-of-line character", fn() { assertEquals(detect(LFinput), EOL.LF); }, }); Deno.test({ - name: "[EOL] Detect No New Line", + name: "detect() returns null for a string with no end-of-line character", fn() { assertEquals(detect(NoNLinput), null); }, }); Deno.test({ - name: "[EOL] Detect Mixed", + name: + "detect() detects the most common end-of-line character in a mixed string", fn() { assertEquals(detect(Mixedinput), EOL.CRLF); assertEquals(detect(Mixedinput2), EOL.CRLF); @@ -38,7 +39,7 @@ Deno.test({ }); Deno.test({ - name: "[EOL] Format", + name: "format() converts the end-of-line character to the specified one", fn() { assertEquals(format(CRLFinput, EOL.LF), LFinput); assertEquals(format(LFinput, EOL.LF), LFinput); diff --git a/fs/exists_test.ts b/fs/exists_test.ts index 9d5792e1d065..7327564e723a 100644 --- a/fs/exists_test.ts +++ b/fs/exists_test.ts @@ -3,7 +3,7 @@ import { assertEquals } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { exists, existsSync } from "./exists.ts"; -Deno.test("[fs] existsNotExist", async function () { +Deno.test("exists() returns false for a non-existent path", async function () { const tempDirPath = await Deno.makeTempDir(); try { assertEquals(await exists(path.join(tempDirPath, "not_exists")), false); @@ -12,7 +12,7 @@ Deno.test("[fs] existsNotExist", async function () { } }); -Deno.test("[fs] existsNotExistSync", function () { +Deno.test("existsSync() returns false for a non-existent path", function () { const tempDirPath = Deno.makeTempDirSync(); try { assertEquals(existsSync(path.join(tempDirPath, "not_exists")), false); @@ -21,7 +21,7 @@ Deno.test("[fs] existsNotExistSync", function () { } }); -Deno.test("[fs] existsFile", async function () { +Deno.test("exists() returns true for an existing file", async function () { const tempDirPath = await Deno.makeTempDir(); const tempFilePath = path.join(tempDirPath, "0.ts"); const tempFile = await Deno.create(tempFilePath); @@ -59,7 +59,7 @@ Deno.test("[fs] existsFile", async function () { } }); -Deno.test("[fs] existsFileLink", async function () { +Deno.test("exists() returns true for an existing file symlink", async function () { const tempDirPath = await Deno.makeTempDir(); const tempFilePath = path.join(tempDirPath, "0.ts"); const tempLinkFilePath = path.join(tempDirPath, "0-link.ts"); @@ -100,7 +100,7 @@ Deno.test("[fs] existsFileLink", async function () { } }); -Deno.test("[fs] existsFileSync", function () { +Deno.test("existsSync() returns true for an existing file", function () { const tempDirPath = Deno.makeTempDirSync(); const tempFilePath = path.join(tempDirPath, "0.ts"); const tempFile = Deno.createSync(tempFilePath); @@ -138,7 +138,7 @@ Deno.test("[fs] existsFileSync", function () { } }); -Deno.test("[fs] existsFileLinkSync", function () { +Deno.test("existsSync() returns true for an existing file symlink", function () { const tempDirPath = Deno.makeTempDirSync(); const tempFilePath = path.join(tempDirPath, "0.ts"); const tempLinkFilePath = path.join(tempDirPath, "0-link.ts"); @@ -179,7 +179,7 @@ Deno.test("[fs] existsFileLinkSync", function () { } }); -Deno.test("[fs] existsDir", async function () { +Deno.test("exists() returns true for an existing dir", async function () { const tempDirPath = await Deno.makeTempDir(); try { assertEquals(await exists(tempDirPath), true); @@ -214,7 +214,7 @@ Deno.test("[fs] existsDir", async function () { } }); -Deno.test("[fs] existsDirLink", async function () { +Deno.test("exists() returns true for an existing dir symlink", async function () { const tempDirPath = await Deno.makeTempDir(); const tempLinkDirPath = path.join(tempDirPath, "temp-link"); try { @@ -252,7 +252,7 @@ Deno.test("[fs] existsDirLink", async function () { } }); -Deno.test("[fs] existsDirSync", function () { +Deno.test("existsSync() returns true for an existing dir", function () { const tempDirPath = Deno.makeTempDirSync(); try { assertEquals(existsSync(tempDirPath), true); @@ -287,7 +287,7 @@ Deno.test("[fs] existsDirSync", function () { } }); -Deno.test("[fs] existsDirLinkSync", function () { +Deno.test("existsSync() returns true for an existing dir symlink", function () { const tempDirPath = Deno.makeTempDirSync(); const tempLinkDirPath = path.join(tempDirPath, "temp-link"); try { diff --git a/fs/expand_glob_test.ts b/fs/expand_glob_test.ts index 120622ea1f38..b3453ba64371 100644 --- a/fs/expand_glob_test.ts +++ b/fs/expand_glob_test.ts @@ -23,16 +23,31 @@ async function expandGlobArray( ({ path }) => path, ); paths.sort(); + const root = normalize(forceRoot || options.root || Deno.cwd()); + for (const path of paths) { + assert(path.startsWith(root)); + } + const relativePaths = paths.map( + (path: string): string => relative(root, path) || ".", + ); + relativePaths.sort(); + return relativePaths; +} + +function expandGlobSyncArray( + globString: string, + options: ExpandGlobOptions, + { forceRoot = "" } = {}, +): string[] { const pathsSync = [...expandGlobSync(globString, options)].map( ({ path }): string => path, ); pathsSync.sort(); - assertEquals(paths, pathsSync); const root = normalize(forceRoot || options.root || Deno.cwd()); - for (const path of paths) { + for (const path of pathsSync) { assert(path.startsWith(root)); } - const relativePaths = paths.map( + const relativePaths = pathsSync.map( (path: string): string => relative(root, path) || ".", ); relativePaths.sort(); @@ -45,7 +60,7 @@ const EG_OPTIONS: ExpandGlobOptions = { extended: false, }; -Deno.test("expandGlobWildcard", async function () { +Deno.test("expandGlob() with wildcard input returns all test data", async function () { const options = EG_OPTIONS; assertEquals(await expandGlobArray("*", options), [ "a[b]c", @@ -57,7 +72,19 @@ Deno.test("expandGlobWildcard", async function () { ]); }); -Deno.test("expandGlobTrailingSeparator", async function () { +Deno.test("expandGlobSync() with wildcard input returns all test data", function () { + const options = EG_OPTIONS; + assertEquals(expandGlobSyncArray("*", options), [ + "a[b]c", + "abc", + "abcdef", + "abcdefghi", + "link", + "subdir", + ]); +}); + +Deno.test("expandGlob() with */ input returns subdirs", async function () { const options = EG_OPTIONS; assertEquals(await expandGlobArray("*/", options), [ "a[b]c", @@ -65,7 +92,15 @@ Deno.test("expandGlobTrailingSeparator", async function () { ]); }); -Deno.test("expandGlobParent", async function () { +Deno.test("expandGlobSync() with */ input returns subdirs", function () { + const options = EG_OPTIONS; + assertEquals(expandGlobSyncArray("*/", options), [ + "a[b]c", + "subdir", + ]); +}); + +Deno.test("expandGlob() with subdir/../* input expands parent", async function () { const options = EG_OPTIONS; assertEquals(await expandGlobArray("subdir/../*", options), [ "a[b]c", @@ -77,7 +112,19 @@ Deno.test("expandGlobParent", async function () { ]); }); -Deno.test("expandGlobExt", async function () { +Deno.test("expandGlobSync() with subdir/../* input expands parent", function () { + const options = EG_OPTIONS; + assertEquals(expandGlobSyncArray("subdir/../*", options), [ + "a[b]c", + "abc", + "abcdef", + "abcdefghi", + "link", + "subdir", + ]); +}); + +Deno.test("expandGlob() accepts extended option set as true", async function () { const options = { ...EG_OPTIONS, extended: true }; assertEquals(await expandGlobArray("abc?(def|ghi)", options), [ "abc", @@ -97,7 +144,27 @@ Deno.test("expandGlobExt", async function () { assertEquals(await expandGlobArray("abc!(def|ghi)", options), ["abc"]); }); -Deno.test("expandGlobGlobstar", async function () { +Deno.test("expandGlobSync() accepts extended option set as true", function () { + const options = { ...EG_OPTIONS, extended: true }; + assertEquals(expandGlobSyncArray("abc?(def|ghi)", options), [ + "abc", + "abcdef", + ]); + assertEquals(expandGlobSyncArray("abc*(def|ghi)", options), [ + "abc", + "abcdef", + "abcdefghi", + ]); + assertEquals(expandGlobSyncArray("abc+(def|ghi)", options), [ + "abcdef", + "abcdefghi", + ]); + assertEquals(expandGlobSyncArray("abc@(def|ghi)", options), ["abcdef"]); + assertEquals(expandGlobSyncArray("abc{def,ghi}", options), ["abcdef"]); + assertEquals(expandGlobSyncArray("abc!(def|ghi)", options), ["abc"]); +}); + +Deno.test("expandGlob() with globstar returns all dirs", async function () { const options = { ...EG_OPTIONS }; assertEquals( await expandGlobArray("**/abc", options), @@ -105,7 +172,15 @@ Deno.test("expandGlobGlobstar", async function () { ); }); -Deno.test("expandGlobGlobstarParent", async function () { +Deno.test("expandGlobSync() with globstar returns all dirs", function () { + const options = { ...EG_OPTIONS }; + assertEquals( + expandGlobSyncArray("**/abc", options), + ["abc", join("subdir", "abc")], + ); +}); + +Deno.test("expandGlob() with globstar parent returns all dirs", async function () { const options = { ...EG_OPTIONS, globstar: true }; assertEquals( await expandGlobArray(joinGlobs(["subdir", "**", ".."], options), options), @@ -113,7 +188,15 @@ Deno.test("expandGlobGlobstarParent", async function () { ); }); -Deno.test("expandGlobGlobstarFalseWithGlob", async function () { +Deno.test("expandGlobSync() with globstar parent returns all dirs", function () { + const options = { ...EG_OPTIONS, globstar: true }; + assertEquals( + expandGlobSyncArray(joinGlobs(["subdir", "**", ".."], options), options), + ["."], + ); +}); + +Deno.test("expandGlob() with globstar parent and globstar option set to false returns current dir", async function () { const options = { ...EG_OPTIONS, globstar: false }; assertEquals(await expandGlobArray("**", options), [ ".", @@ -126,12 +209,30 @@ Deno.test("expandGlobGlobstarFalseWithGlob", async function () { ]); }); -Deno.test("expandGlobIncludeDirs", async function () { +Deno.test("expandGlobSync() with globstar parent and globstar option set to false returns current dir", function () { + const options = { ...EG_OPTIONS, globstar: false }; + assertEquals(expandGlobSyncArray("**", options), [ + ".", + "a[b]c", + "abc", + "abcdef", + "abcdefghi", + "link", + "subdir", + ]); +}); + +Deno.test("expandGlob() accepts includeDirs option set to false", async function () { const options = { ...EG_OPTIONS, includeDirs: false }; assertEquals(await expandGlobArray("subdir", options), []); }); -Deno.test("expandGlobPermError", async function () { +Deno.test("expandGlobSync() accepts includeDirs option set to false", function () { + const options = { ...EG_OPTIONS, includeDirs: false }; + assertEquals(expandGlobSyncArray("subdir", options), []); +}); + +Deno.test("expandGlob() throws permission error without fs permissions", async function () { const exampleUrl = new URL("testdata/expand_wildcard.js", import.meta.url); const command = new Deno.Command(Deno.execPath(), { args: ["run", "--quiet", "--unstable", exampleUrl.toString()], @@ -144,12 +245,17 @@ Deno.test("expandGlobPermError", async function () { assertStringIncludes(decoder.decode(stderr), "Uncaught PermissionDenied"); }); -Deno.test("expandGlobRootIsNotGlob", async function () { +Deno.test("expandGlob() returns single entry when root is not glob", async function () { const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "a[b]c") }; assertEquals(await expandGlobArray("*", options), ["foo"]); }); -Deno.test("expandGlobFollowSymlink", async function () { +Deno.test("expandGlobSync() returns single entry when root is not glob", function () { + const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "a[b]c") }; + assertEquals(expandGlobSyncArray("*", options), ["foo"]); +}); + +Deno.test("expandGlob() accepts followSymlinks option set to true", async function () { const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "link"), @@ -158,7 +264,16 @@ Deno.test("expandGlobFollowSymlink", async function () { assertEquals(await expandGlobArray("*", options), ["abc"]); }); -Deno.test("expandGlobFollowSymlink with canonicalize", async function () { +Deno.test("expandGlobSync() accepts followSymlinks option set to true", function () { + const options = { + ...EG_OPTIONS, + root: join(EG_OPTIONS.root!, "link"), + followSymlinks: true, + }; + assertEquals(expandGlobSyncArray("*", options), ["abc"]); +}); + +Deno.test("expandGlob() accepts followSymlinks option set to true with canonicalize", async function () { const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "."), @@ -170,7 +285,19 @@ Deno.test("expandGlobFollowSymlink with canonicalize", async function () { ); }); -Deno.test("expandGlobFollowSymlink without canonicalize", async function () { +Deno.test("expandGlobSync() accepts followSymlinks option set to true with canonicalize", function () { + const options = { + ...EG_OPTIONS, + root: join(EG_OPTIONS.root!, "."), + followSymlinks: true, + }; + assertEquals( + expandGlobSyncArray("**/abc", options), + ["abc", join("subdir", "abc")], + ); +}); + +Deno.test("expandGlob() accepts followSymlinks option set to true without canonicalize", async function () { const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "."), @@ -183,8 +310,21 @@ Deno.test("expandGlobFollowSymlink without canonicalize", async function () { ); }); +Deno.test("expandGlobSync() accepts followSymlinks option set to true without canonicalize", function () { + const options = { + ...EG_OPTIONS, + root: join(EG_OPTIONS.root!, "."), + followSymlinks: true, + canonicalize: false, + }; + assertEquals( + expandGlobSyncArray("**/abc", options), + ["abc", join("link", "abc"), join("subdir", "abc")], + ); +}); + Deno.test( - "expandGlob doesn't require read permissions when root path is specified", + "expandGlob() does not require read permissions when root path is specified", { permissions: { read: [EG_OPTIONS.root!] }, }, @@ -195,7 +335,18 @@ Deno.test( ); Deno.test( - "expandGlob doesn't require read permissions when an absolute glob is specified", + "expandGlobSync() does not require read permissions when root path is specified", + { + permissions: { read: [EG_OPTIONS.root!] }, + }, + function () { + const options = { root: EG_OPTIONS.root! }; + assertEquals(expandGlobSyncArray("abc", options), ["abc"]); + }, +); + +Deno.test( + "expandGlob() does not require read permissions when an absolute glob is specified", { permissions: { read: [EG_OPTIONS.root!] }, }, @@ -208,3 +359,18 @@ Deno.test( ); }, ); + +Deno.test( + "expandGlobSync() does not require read permissions when an absolute glob is specified", + { + permissions: { read: [EG_OPTIONS.root!] }, + }, + function () { + assertEquals( + expandGlobSyncArray(`${EG_OPTIONS.root!}/abc`, {}, { + forceRoot: EG_OPTIONS.root!, + }), + ["abc"], + ); + }, +); diff --git a/fs/move_test.ts b/fs/move_test.ts index e5032974e202..2b31ba41e34e 100644 --- a/fs/move_test.ts +++ b/fs/move_test.ts @@ -14,7 +14,7 @@ import { existsSync } from "./exists.ts"; const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); const testdataDir = path.resolve(moduleDir, "testdata"); -Deno.test("moveDirectoryIfSrcNotExists", async function () { +Deno.test("move() rejects if src dir does not exist", async function () { const srcDir = path.join(testdataDir, "move_test_src_1"); const destDir = path.join(testdataDir, "move_test_dest_1"); // if src directory not exist @@ -25,7 +25,7 @@ Deno.test("moveDirectoryIfSrcNotExists", async function () { ); }); -Deno.test("moveDirectoryIfDestNotExists", async function () { +Deno.test("move() creates dest dir if it does not exist", async function () { const srcDir = path.join(testdataDir, "move_test_src_2"); const destDir = path.join(testdataDir, "move_test_dest_2"); @@ -45,7 +45,7 @@ Deno.test("moveDirectoryIfDestNotExists", async function () { }); Deno.test( - "moveDirectoryIfDestNotExistsAndOverwrite", + "move() creates dest dir if it does not exist and overwrite option is set to true", async function () { const srcDir = path.join(testdataDir, "move_test_src_2"); const destDir = path.join(testdataDir, "move_test_dest_2"); @@ -66,7 +66,7 @@ Deno.test( }, ); -Deno.test("moveFileIfSrcNotExists", async function () { +Deno.test("move() rejects if src file does not exist", async function () { const srcFile = path.join(testdataDir, "move_test_src_3", "test.txt"); const destFile = path.join(testdataDir, "move_test_dest_3", "test.txt"); @@ -78,7 +78,7 @@ Deno.test("moveFileIfSrcNotExists", async function () { ); }); -Deno.test("moveFileIfDestExists", async function () { +Deno.test("move() moves file and can overwrite content", async function () { 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"); @@ -128,7 +128,7 @@ Deno.test("moveFileIfDestExists", async function () { ]); }); -Deno.test("moveDirectory", async function () { +Deno.test("move() moves dir", async function () { 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"); @@ -152,7 +152,7 @@ Deno.test("moveDirectory", async function () { }); Deno.test( - "moveIfSrcAndDestDirectoryExistsAndOverwrite", + "move() moves files if src and dest exist and can overwrite content", async function () { const srcDir = path.join(testdataDir, "move_test_src_6"); const destDir = path.join(testdataDir, "move_test_dest_6"); @@ -185,7 +185,7 @@ Deno.test( }, ); -Deno.test("moveIntoSubDir", async function () { +Deno.test("move() rejects when dest is its own sub dir", async function () { const srcDir = path.join(testdataDir, "move_test_src_7"); const destDir = path.join(srcDir, "nest"); @@ -201,7 +201,7 @@ Deno.test("moveIntoSubDir", async function () { await Deno.remove(srcDir, { recursive: true }); }); -Deno.test("moveSyncDirectoryIfSrcNotExists", function () { +Deno.test("moveSync() throws if src dir does not exist", function () { 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 @@ -210,7 +210,7 @@ Deno.test("moveSyncDirectoryIfSrcNotExists", function () { }); }); -Deno.test("moveSyncDirectoryIfDestNotExists", function () { +Deno.test("moveSync() creates dest dir if it does not exist", function () { const srcDir = path.join(testdataDir, "move_sync_test_src_2"); const destDir = path.join(testdataDir, "move_sync_test_dest_2"); @@ -229,7 +229,7 @@ Deno.test("moveSyncDirectoryIfDestNotExists", function () { Deno.removeSync(destDir); }); -Deno.test("moveSyncDirectoryIfDestNotExistsAndOverwrite", function () { +Deno.test("moveSync() creates dest dir if it does not exist and overwrite option is set to true", function () { const srcDir = path.join(testdataDir, "move_sync_test_src_2"); const destDir = path.join(testdataDir, "move_sync_test_dest_2"); @@ -248,7 +248,7 @@ Deno.test("moveSyncDirectoryIfDestNotExistsAndOverwrite", function () { Deno.removeSync(destDir); }); -Deno.test("moveSyncFileIfSrcNotExists", function () { +Deno.test("moveSync() throws if src file does not exist", function () { const srcFile = path.join(testdataDir, "move_sync_test_src_3", "test.txt"); const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt"); @@ -258,7 +258,7 @@ Deno.test("moveSyncFileIfSrcNotExists", function () { }); }); -Deno.test("moveSyncFileIfDestExists", function () { +Deno.test("moveSync() moves file and can overwrite content", function () { 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"); @@ -305,7 +305,7 @@ Deno.test("moveSyncFileIfDestExists", function () { Deno.removeSync(destDir, { recursive: true }); }); -Deno.test("moveSyncDirectory", function () { +Deno.test("moveSync() moves dir", function () { 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"); @@ -328,7 +328,7 @@ Deno.test("moveSyncDirectory", function () { Deno.removeSync(destDir, { recursive: true }); }); -Deno.test("moveSyncIfSrcAndDestDirectoryExistsAndOverwrite", function () { +Deno.test("moveSync() moves files if src and dest exist and can overwrite content", function () { 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"); @@ -355,7 +355,7 @@ Deno.test("moveSyncIfSrcAndDestDirectoryExistsAndOverwrite", function () { Deno.removeSync(destDir, { recursive: true }); }); -Deno.test("moveSyncIntoSubDir", function () { +Deno.test("moveSync() throws when dest is its own sub dir", function () { const srcDir = path.join(testdataDir, "move_sync_test_src_7"); const destDir = path.join(srcDir, "nest"); @@ -371,7 +371,7 @@ Deno.test("moveSyncIntoSubDir", function () { Deno.removeSync(srcDir, { recursive: true }); }); -Deno.test("moveSameFileOverwrite", async function () { +Deno.test("move() accepts overwrite option set to true for file content", async function () { const dir = path.join(testdataDir, "move_same_file_1"); const file = path.join(dir, "test.txt"); const url = path.toFileUrl(file); @@ -401,7 +401,7 @@ Deno.test("moveSameFileOverwrite", async function () { await Deno.remove(dir, { recursive: true }); }); -Deno.test("moveSameDirOverwrite", async function () { +Deno.test("move() accepts overwrite option set to true for directories", async function () { const dir = path.join(testdataDir, "move_same_dir_1"); const url = path.toFileUrl(dir); @@ -429,7 +429,7 @@ Deno.test("moveSameDirOverwrite", async function () { await Deno.remove(dir, { recursive: true }); }); -Deno.test("moveSyncSameFileOverwrite", function () { +Deno.test("moveSync() accepts overwrite option set to true for file content", function () { const dir = path.join(testdataDir, "move_sync_same_file_1"); const file = path.join(dir, "test.txt"); const url = path.toFileUrl(file); @@ -459,7 +459,7 @@ Deno.test("moveSyncSameFileOverwrite", function () { Deno.removeSync(dir, { recursive: true }); }); -Deno.test("moveSyncSameDirOverwrite", function () { +Deno.test("move() accepts overwrite option set to true for directories", function () { const dir = path.join(testdataDir, "move_sync_same_dir_1"); const url = path.toFileUrl(dir); diff --git a/fs/walk_test.ts b/fs/walk_test.ts index 897f9fd3de20..a77564b75e6b 100644 --- a/fs/walk_test.ts +++ b/fs/walk_test.ts @@ -17,83 +17,154 @@ async function assertWalkPaths( ) { const root = resolve(testdataDir, rootPath); const entries = await Array.fromAsync(walk(root, options)); - const entriesSync = Array.from(walkSync(root, options)); const expected = expectedPaths.map((path) => resolve(root, path)); - assertEquals(entries, entriesSync); assertEquals(entries.length, expected.length); assertArrayIncludes(entries.map(({ path }) => path), expected); } -Deno.test("[fs/walk] empty dir", async () => { +function assertWalkSyncPaths( + rootPath: string, + expectedPaths: string[], + options?: WalkOptions, +) { + const root = resolve(testdataDir, rootPath); + const entriesSync = Array.from(walkSync(root, options)); + + const expected = expectedPaths.map((path) => resolve(root, path)); + assertEquals(entriesSync.length, expected.length); + assertArrayIncludes(entriesSync.map(({ path }) => path), expected); +} + +Deno.test("walk() returns current dir for empty dir", async () => { const emptyDir = resolve(testdataDir, "empty_dir"); await Deno.mkdir(emptyDir); await assertWalkPaths("empty_dir", ["."]); await Deno.remove(emptyDir); }); -Deno.test("[fs/walk] single file", async () => +Deno.test("walkSync() returns current dir for empty dir", async () => { + const emptyDir = resolve(testdataDir, "empty_dir"); + await Deno.mkdir(emptyDir); + assertWalkSyncPaths("empty_dir", ["."]); + await Deno.remove(emptyDir); +}); + +Deno.test("walk() returns current dir and single file", async () => await assertWalkPaths("single_file", [".", "x"])); -Deno.test("[fs/walk] nested single file", async () => +Deno.test("walkSync() returns current dir and single file", () => + assertWalkSyncPaths("single_file", [".", "x"])); + +Deno.test("walk() returns current dir, subdir, and nested file", async () => await assertWalkPaths("nested_single_file", [".", "a", "a/x"])); -Deno.test("[fs/walk] max depth", async () => +Deno.test("walkSync() returns current dir, subdir, and nested file", () => + assertWalkSyncPaths("nested_single_file", [".", "a", "a/x"])); + +Deno.test("walk() accepts maxDepth option", async () => await assertWalkPaths("depth", [".", "a", "a/b", "a/b/c"], { maxDepth: 3 })); -Deno.test("[fs/walk] exclude dirs", async () => +Deno.test("walkSync() accepts maxDepth option", () => + assertWalkSyncPaths("depth", [".", "a", "a/b", "a/b/c"], { maxDepth: 3 })); + +Deno.test("walk() accepts includeDirs option set to false", async () => await assertWalkPaths("depth", ["a/b/c/d/x"], { includeDirs: false })); -Deno.test("[fs/walk] exclude files", async () => +Deno.test("walkSync() accepts includeDirs option set to false", () => + assertWalkSyncPaths("depth", ["a/b/c/d/x"], { includeDirs: false })); + +Deno.test("walk() accepts includeFiles option set to false", async () => await assertWalkPaths("depth", [".", "a", "a/b", "a/b/c", "a/b/c/d"], { includeFiles: false, })); -Deno.test("[fs/walk] ext", async () => +Deno.test("walkSync() accepts includeFiles option set to false", () => + assertWalkSyncPaths("depth", [".", "a", "a/b", "a/b/c", "a/b/c/d"], { + includeFiles: false, + })); + +Deno.test("walk() accepts ext option as strings", async () => await assertWalkPaths("ext", ["y.rs", "x.ts"], { exts: [".rs", ".ts"], })); -Deno.test("[fs/walk] ext", async () => +Deno.test("walkSync() accepts ext option as strings", () => + assertWalkSyncPaths("ext", ["y.rs", "x.ts"], { + exts: [".rs", ".ts"], + })); + +Deno.test("walk() accepts ext option as regExps", async () => await assertWalkPaths("match", ["x", "y"], { match: [/x/, /y/], })); -Deno.test("[fs/walk] skip", async () => +Deno.test("walkSync() accepts ext option as regExps", () => + assertWalkSyncPaths("match", ["x", "y"], { + match: [/x/, /y/], + })); + +Deno.test("walk() accepts skip option as regExps", async () => await assertWalkPaths("match", [".", "z"], { skip: [/x/, /y/], })); +Deno.test("walkSync() accepts skip option as regExps", () => + assertWalkSyncPaths("match", [".", "z"], { + skip: [/x/, /y/], + })); + // https://github.com/denoland/deno_std/issues/1358 -Deno.test("[fs/walk] symlink", async () => +Deno.test("walk() accepts followSymlinks option set to true", async () => await assertWalkPaths("symlink", [".", "a", "a/z", "a", "a/z", "x", "x"], { followSymlinks: true, })); -Deno.test("[fs/walk] symlink without canonicalize", async () => +Deno.test("walkSync() accepts followSymlinks option set to true", () => + assertWalkSyncPaths("symlink", [".", "a", "a/z", "a", "a/z", "x", "x"], { + followSymlinks: true, + })); + +Deno.test("walk() accepts followSymlinks option set to true with canonicalize option set to false", async () => await assertWalkPaths("symlink", [".", "a", "a/z", "b", "b/z", "x", "y"], { followSymlinks: true, canonicalize: false, })); -Deno.test("[fs/walk] symlink without followSymlink", async () => { +Deno.test("walkSync() accepts followSymlinks option set to true with canonicalize option set to false", () => + assertWalkSyncPaths("symlink", [".", "a", "a/z", "b", "b/z", "x", "y"], { + followSymlinks: true, + canonicalize: false, + })); + +Deno.test("walk() accepts followSymlinks option set to false", async () => { await assertWalkPaths("symlink", [".", "a", "a/z", "b", "x", "y"], { followSymlinks: false, }); }); -Deno.test("[fs/walk] non-existent root", async () => { +Deno.test("walkSync() accepts followSymlinks option set to false", () => { + assertWalkSyncPaths("symlink", [".", "a", "a/z", "b", "x", "y"], { + followSymlinks: false, + }); +}); + +Deno.test("walk() rejects Deno.errors.NotFound for non-existent root", async () => { const root = resolve(testdataDir, "non_existent"); await assertRejects( async () => await Array.fromAsync(walk(root)), Deno.errors.NotFound, ); +}); + +Deno.test("walkSync() throws Deno.errors.NotFound for non-existent root", () => { + const root = resolve(testdataDir, "non_existent"); assertThrows(() => Array.from(walkSync(root)), Deno.errors.NotFound); }); // https://github.com/denoland/deno_std/issues/1789 Deno.test({ - name: "[fs/walk] unix socket", + name: "walk() walks unix socket", ignore: Deno.build.os === "windows", async fn() { const path = resolve(testdataDir, "socket", "a.sock"); @@ -109,8 +180,26 @@ Deno.test({ }, }); +// https://github.com/denoland/deno_std/issues/1789 Deno.test({ - name: "[fs/walk] fifo", + name: "walkSync() walks unix socket", + ignore: Deno.build.os === "windows", + async fn() { + const path = resolve(testdataDir, "socket", "a.sock"); + try { + const listener = Deno.listen({ path, transport: "unix" }); + assertWalkSyncPaths("socket", [".", "a.sock", ".gitignore"], { + followSymlinks: true, + }); + listener.close(); + } finally { + await Deno.remove(path); + } + }, +}); + +Deno.test({ + name: "walk() walks fifo files on unix", ignore: Deno.build.os === "windows", async fn() { const command = new Deno.Command("mkfifo", { @@ -123,13 +212,32 @@ Deno.test({ }, }); -Deno.test("[fs/walk] error", async () => { +Deno.test({ + name: "walkSync() walks fifo files on unix", + ignore: Deno.build.os === "windows", + async fn() { + const command = new Deno.Command("mkfifo", { + args: [resolve(testdataDir, "fifo", "fifo")], + }); + await command.output(); + assertWalkSyncPaths("fifo", [".", "fifo", ".gitignore"], { + followSymlinks: true, + }); + }, +}); + +Deno.test("walk() rejects with WalkError when root is removed during execution", async () => { const root = resolve(testdataDir, "error"); await Deno.mkdir(root); - await assertRejects(async () => { - await Array.fromAsync( - walk(root), - async () => await Deno.remove(root, { recursive: true }), - ); - }, WalkError); + try { + await assertRejects(async () => { + await Array.fromAsync( + walk(root), + async () => await Deno.remove(root, { recursive: true }), + ); + }, WalkError); + } catch (err) { + await Deno.remove(root, { recursive: true }); + throw err; + } });