import assert from "node:assert/strict"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { afterEach, describe, it } from "node:test"; import { getFilesWithFS } from "./getFilesWithFS"; describe("getFilesWithFS", () => { let tempDir = ""; afterEach(async () => { if (tempDir) { await fs.rm(tempDir, { recursive: true, force: true }); tempDir = ""; } }); it("throws when dir is empty", async () => { await assert.rejects(async () => getFilesWithFS("")); }); it("reads files recursively and applies filter", async () => { tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "delement-utils-")); const nestedDir = path.join(tempDir, "nested"); // eslint-disable-next-line security/detect-non-literal-fs-filename await fs.mkdir(nestedDir); const firstFile = path.join(tempDir, "one.txt"); const secondFile = path.join(nestedDir, "two.json"); // eslint-disable-next-line security/detect-non-literal-fs-filename await fs.writeFile(firstFile, "one"); // eslint-disable-next-line security/detect-non-literal-fs-filename await fs.writeFile(secondFile, "two"); const files = await getFilesWithFS(tempDir, (file) => file.endsWith(".json")); assert.strictEqual(files.length, 1); assert.strictEqual(files[0], secondFile); }); });