test: improve test coverage (#7113)

This commit is contained in:
Joshua Chen 2022-04-05 14:09:19 +08:00 committed by GitHub
parent 4194925da9
commit e610a4ac00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 235 additions and 61 deletions

View file

@ -83,18 +83,16 @@ export async function readOutputHTMLFile(
outDir,
`${permalink.replace(/\/$/, '')}.html`,
);
if (trailingSlash) {
return fs.readFile(withTrailingSlashPath);
} else if (trailingSlash === false) {
return fs.readFile(withoutTrailingSlashPath);
}
const HTMLPath = await findAsyncSequential(
[withTrailingSlashPath, withoutTrailingSlashPath],
[
trailingSlash !== false && withTrailingSlashPath,
trailingSlash !== true && withoutTrailingSlashPath,
].filter((p): p is string => Boolean(p)),
fs.pathExists,
);
if (!HTMLPath) {
throw new Error(
`Expected output HTML file to be found at ${withTrailingSlashPath}`,
`Expected output HTML file to be found at ${withTrailingSlashPath}.`,
);
}
return fs.readFile(HTMLPath);