feat(testing): refactor humanPath and add tests (#4511)

* feat: add test for humanPath

* refactor: make humanPath pure and pass in homedir
This commit is contained in:
Joe Previte
2021-11-15 19:40:34 +00:00
committed by GitHub
parent 16a5f2e171
commit 0a072f7532
5 changed files with 31 additions and 12 deletions

View File

@@ -88,16 +88,17 @@ export function getEnvPaths(): Paths {
}
/**
* humanPath replaces the home directory in p with ~.
* humanPath replaces the home directory in path with ~.
* Makes it more readable.
*
* @param p
* @param homedir - the home directory(i.e. `os.homedir()`)
* @param path - a file path
*/
export function humanPath(p?: string): string {
if (!p) {
export function humanPath(homedir: string, path?: string): string {
if (!path) {
return ""
}
return p.replace(os.homedir(), "~")
return path.replace(homedir, "~")
}
export const generateCertificate = async (hostname: string): Promise<{ cert: string; certKey: string }> => {