Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b45b356

Browse files
committed
Add isDirectory test
1 parent d11bb41 commit b45b356

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

test/unit/node/util.test.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,40 @@ describe("isFile", () => {
457457
afterEach(async () => {
458458
await fs.rm(testDir, { recursive: true, force: true })
459459
})
460-
it("should return false if the path doesn't exist", async () => {
460+
it("should return false if is directory", async () => {
461461
expect(await util.isFile(testDir)).toBe(false)
462462
})
463463
it("should return true if is file", async () => {
464464
expect(await util.isFile(pathToFile)).toBe(true)
465465
})
466-
it("should return false if error", async () => {
466+
it("should return false if the path doesn't exist", async () => {
467467
expect(await util.isFile("fakefile.txt")).toBe(false)
468468
})
469469
})
470470

471+
describe("isDirectory", () => {
472+
const testDir = path.join(tmpdir, "tests", "isDirectory")
473+
let pathToFile = ""
474+
475+
beforeEach(async () => {
476+
pathToFile = path.join(testDir, "foo.txt")
477+
await fs.mkdir(testDir, { recursive: true })
478+
await fs.writeFile(pathToFile, "hello")
479+
})
480+
afterEach(async () => {
481+
await fs.rm(testDir, { recursive: true, force: true })
482+
})
483+
it("should return false if is a file", async () => {
484+
expect(await util.isDirectory(pathToFile)).toBe(false)
485+
})
486+
it("should return true if is directory", async () => {
487+
expect(await util.isDirectory(testDir)).toBe(true)
488+
})
489+
it("should return false if the path doesn't exist", async () => {
490+
expect(await util.isDirectory("fakefile.txt")).toBe(false)
491+
})
492+
})
493+
471494
describe("humanPath", () => {
472495
it("should return an empty string if no path provided", () => {
473496
const mockHomedir = "/home/coder"

0 commit comments

Comments
 (0)