From b45b35603a0fecf95b20ea42228339bc0099036e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 6 Oct 2022 19:14:48 +0200 Subject: [PATCH] Add isDirectory test --- test/unit/node/util.test.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/test/unit/node/util.test.ts b/test/unit/node/util.test.ts index aea682ba..e3866767 100644 --- a/test/unit/node/util.test.ts +++ b/test/unit/node/util.test.ts @@ -457,17 +457,40 @@ describe("isFile", () => { afterEach(async () => { await fs.rm(testDir, { recursive: true, force: true }) }) - it("should return false if the path doesn't exist", async () => { + it("should return false if is directory", async () => { expect(await util.isFile(testDir)).toBe(false) }) it("should return true if is file", async () => { expect(await util.isFile(pathToFile)).toBe(true) }) - it("should return false if error", async () => { + it("should return false if the path doesn't exist", async () => { expect(await util.isFile("fakefile.txt")).toBe(false) }) }) +describe("isDirectory", () => { + const testDir = path.join(tmpdir, "tests", "isDirectory") + let pathToFile = "" + + beforeEach(async () => { + pathToFile = path.join(testDir, "foo.txt") + await fs.mkdir(testDir, { recursive: true }) + await fs.writeFile(pathToFile, "hello") + }) + afterEach(async () => { + await fs.rm(testDir, { recursive: true, force: true }) + }) + it("should return false if is a file", async () => { + expect(await util.isDirectory(pathToFile)).toBe(false) + }) + it("should return true if is directory", async () => { + expect(await util.isDirectory(testDir)).toBe(true) + }) + it("should return false if the path doesn't exist", async () => { + expect(await util.isDirectory("fakefile.txt")).toBe(false) + }) +}) + describe("humanPath", () => { it("should return an empty string if no path provided", () => { const mockHomedir = "/home/coder"