Skip to content

Commit 8d1e5d4

Browse files
author
Joe
committed
feat: add test for humanPath
1 parent 16a5f2e commit 8d1e5d4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/node/util.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ export function getEnvPaths(): Paths {
8888
}
8989

9090
/**
91-
* humanPath replaces the home directory in p with ~.
91+
* humanPath replaces the home directory in path with ~.
9292
* Makes it more readable.
9393
*
94-
* @param p
94+
* @param path - a file path
9595
*/
96-
export function humanPath(p?: string): string {
97-
if (!p) {
96+
export function humanPath(path?: string): string {
97+
if (!path) {
9898
return ""
9999
}
100-
return p.replace(os.homedir(), "~")
100+
return path.replace(os.homedir(), "~")
101101
}
102102

103103
export const generateCertificate = async (hostname: string): Promise<{ cert: string; certKey: string }> => {

test/unit/node/util.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,16 @@ describe("isFile", () => {
476476
expect(await util.isFile(pathToFile)).toBe(true)
477477
})
478478
})
479+
480+
describe("humanPath", () => {
481+
it("should return an empty string if no path provided", () => {
482+
const actual = util.humanPath()
483+
const expected = ""
484+
expect(actual).toBe(expected)
485+
})
486+
it("should replace the homedir with ~", () => {
487+
const actual = util.humanPath(`/home/coder/code-server`)
488+
const expected = "~/code-server"
489+
expect(actual).toBe(expected)
490+
})
491+
})

0 commit comments

Comments
 (0)