Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Mar 28, 2024
1 parent 1ecce9c commit 8294a45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Empty file added src/stat/find.test.ts
Empty file.
4 changes: 2 additions & 2 deletions src/stat/find.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -62,6 +63,5 @@ export async function find(
);
return results;
}

return []; // Not a directory or file
}
43 changes: 20 additions & 23 deletions src/stat/is.test.ts
Original file line number Diff line number Diff line change
@@ -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,
);
});

0 comments on commit 8294a45

Please sign in to comment.