From 8294a455422662140561f98c8cd8901fc07fe05a Mon Sep 17 00:00:00 2001 From: Hexagon Date: Thu, 28 Mar 2024 21:15:17 +0100 Subject: [PATCH] Add test --- src/stat/find.test.ts | 0 src/stat/find.ts | 4 ++-- src/stat/is.test.ts | 43 ++++++++++++++++++++----------------------- 3 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 src/stat/find.test.ts diff --git a/src/stat/find.test.ts b/src/stat/find.test.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/stat/find.ts b/src/stat/find.ts index e4f578f..4572c1e 100644 --- a/src/stat/find.ts +++ b/src/stat/find.ts @@ -1,5 +1,6 @@ import { readdir } from "node:fs/promises"; -import { stat, StatResult } from "./mod.ts"; +import { stat } from "./mod.ts"; +import type { StatResult } from "./mod.ts"; import { join, resolve } from "@std/path"; /** @@ -62,6 +63,5 @@ export async function find( ); return results; } - return []; // Not a directory or file } diff --git a/src/stat/is.test.ts b/src/stat/is.test.ts index 1751b6c..459b616 100644 --- a/src/stat/is.test.ts +++ b/src/stat/is.test.ts @@ -1,29 +1,26 @@ import { assertEquals } from "@std/assert"; import { test } from "@cross/test"; +import { find } from "./find.ts"; -import { isDir, isFile } from "./is.ts"; - -test("isFile returns true on existing file", async () => { - const result = await isFile("./mod.ts"); - assertEquals(result, true); -}); - -test("isFile returns false on non-existiantfile", async () => { - const result = await isFile("./mod-nonexistant.ts"); - assertEquals(result, false); -}); - -test("isDir returns false on existing file", async () => { - const result = await isDir("./mod.ts"); - assertEquals(result, false); -}); - -test("isFile returns false on existing dir", async () => { - const result = await isFile("./src"); - assertEquals(result, false); +test("find locates find.test.ts file", async () => { + const results = await find(".", (path) => path.endsWith("find.test.ts")); + assertEquals(results.length > 0, true); + assertEquals( + results.find((path) => path.includes("/src/stat/find.test.ts"))?.includes( + "/src/stat/find.test.ts", + ), + true, + ); }); -test("isDir returns true on existing dir", async () => { - const result = await isDir("./src"); - assertEquals(result, true); +test("find doest not locate findnonexistant.test.ts file", async () => { + const results = await find( + ".", + (path) => path.endsWith("findnonexistant.test.ts"), + ); + assertEquals(results.length === 0, true); + assertEquals( + results.find((path) => path.includes("/src/stat/findnonexistant.test.ts")), + undefined, + ); });