Update snapshot for checkWorkingDirectory test

This commit is contained in:
Cina Saffary 2023-08-29 17:43:29 -05:00
parent e5251df521
commit 105f191b19
2 changed files with 10 additions and 24 deletions

View file

@ -47,18 +47,10 @@ describe("checkWorkingDirectory", () => {
});
test("should fail if the directory does not exist", () => {
try {
checkWorkingDirectory("/does/not/exist");
} catch (error) {
expect(error.message).toMatchInlineSnapshot();
}
});
test("should fail if an error occurs while checking/creating the directory", () => {
try {
checkWorkingDirectory("/does/not/exist");
} catch (error) {
expect(error.message).toMatchInlineSnapshot();
}
expect(() =>
checkWorkingDirectory("/does/not/exist"),
).toThrowErrorMatchingInlineSnapshot(
'"Directory /does/not/exist does not exist."',
);
});
});

View file

@ -113,17 +113,11 @@ async function runProcess(
}
function checkWorkingDirectory(workingDirectory = ".") {
try {
const normalizedPath = path.normalize(workingDirectory);
if (existsSync(normalizedPath)) {
return normalizedPath;
} else {
throw new Error(`Directory ${workingDirectory} does not exist.`);
}
} catch (error) {
throw new Error(
`While checking/creating directory ${workingDirectory} received ${error}`,
);
const normalizedPath = path.normalize(workingDirectory);
if (existsSync(normalizedPath)) {
return normalizedPath;
} else {
throw new Error(`Directory ${workingDirectory} does not exist.`);
}
}