mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
test: improve test coverage (#7113)
This commit is contained in:
parent
4194925da9
commit
e610a4ac00
17 changed files with 235 additions and 61 deletions
|
@ -11,7 +11,7 @@ import path from 'path';
|
|||
import fs from 'fs-extra';
|
||||
|
||||
describe('readOutputHTMLFile', () => {
|
||||
it('trailing slash undefined', async () => {
|
||||
it('reads both files with trailing slash undefined', async () => {
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/file',
|
||||
|
@ -41,7 +41,7 @@ describe('readOutputHTMLFile', () => {
|
|||
).then(String),
|
||||
).resolves.toBe('folder\n');
|
||||
});
|
||||
it('trailing slash true', async () => {
|
||||
it('reads only folder with trailing slash true', async () => {
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/folder',
|
||||
|
@ -57,7 +57,7 @@ describe('readOutputHTMLFile', () => {
|
|||
).then(String),
|
||||
).resolves.toBe('folder\n');
|
||||
});
|
||||
it('trailing slash false', async () => {
|
||||
it('reads only file trailing slash false', async () => {
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/file',
|
||||
|
@ -73,6 +73,18 @@ describe('readOutputHTMLFile', () => {
|
|||
).then(String),
|
||||
).resolves.toBe('file\n');
|
||||
});
|
||||
// Can it ever happen?
|
||||
it('throws if file does not exist', async () => {
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/nonExistent',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
undefined,
|
||||
).then(String),
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Expected output HTML file to be found at <PROJECT_ROOT>/packages/docusaurus-utils/src/__tests__/__fixtures__/build-snap/nonExistent/index.html."`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generate', () => {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue