Archived
1
0

feat: add tests for isFile

This commit is contained in:
Joe Previte 2021-07-19 15:00:32 -07:00
parent 5c61318592
commit 6e33dccb40
No known key found for this signature in database
GPG Key ID: 2C91590C6B742C24

View File

@ -1,6 +1,9 @@
import * as cp from "child_process"
import * as path from "path"
import { promises as fs } from "fs"
import { generateUuid } from "../../../src/common/util"
import * as util from "../../../src/node/util"
import { tmpdir } from "../../../src/node/constants"
describe("getEnvPaths", () => {
describe("on darwin", () => {
@ -464,9 +467,6 @@ describe("pathToFsPath", () => {
it("should keep drive letter casing when set to true", () => {
expect(util.pathToFsPath("/C:/far/bo", true)).toBe("C:/far/bo")
})
it("should use the first string in a string array", () => {
expect(util.pathToFsPath("/hello/foo")).toBe("/hello/foo")
})
it("should replace / with \\ on Windows", () => {
let ORIGINAL_PLATFORM = process.platform
@ -481,3 +481,23 @@ describe("pathToFsPath", () => {
})
})
})
describe("isFile", () => {
const testDir = path.join(tmpdir, "tests", "isFile")
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 the path doesn't exist", async () => {
expect(await util.isFile(testDir)).toBe(false)
})
it("should return true if is file", async () => {
expect(await util.isFile(pathToFile)).toBe(true)
})
})