test: improve test coverage (#6387)

* test: improve test coverage

* fix

* use posixPath
This commit is contained in:
Joshua Chen 2022-01-18 16:29:40 +08:00 committed by GitHub
parent a9810db1cc
commit 62223ee556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 463 additions and 60 deletions

View file

@ -7,7 +7,7 @@
import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
import type {BlogPost} from './types';
import {normalizeUrl, mdxToHtml} from '@docusaurus/utils';
import {normalizeUrl, mdxToHtml, posixPath} from '@docusaurus/utils';
import type {DocusaurusConfig} from '@docusaurus/types';
import path from 'path';
import fs from 'fs-extra';
@ -30,7 +30,7 @@ function mdxToFeedContent(mdxContent: string): string | undefined {
}
}
export async function generateBlogFeed({
async function generateBlogFeed({
blogPosts,
options,
siteConfig,
@ -47,9 +47,7 @@ export async function generateBlogFeed({
const {url: siteUrl, baseUrl, title, favicon} = siteConfig;
const blogBaseUrl = normalizeUrl([siteUrl, baseUrl, routeBasePath]);
const updated =
(blogPosts[0] && blogPosts[0].metadata.date) ||
new Date('2015-10-25T16:29:00.000-07:00'); // weird legacy magic date
const updated = blogPosts[0] && blogPosts[0].metadata.date;
const feed = new Feed({
id: blogBaseUrl,
@ -118,7 +116,10 @@ async function createBlogFeedFile({
}
})();
try {
await fs.outputFile(path.join(generatePath, feedPath), feedContent);
await fs.outputFile(
posixPath(path.join(generatePath, feedPath)),
feedContent,
);
} catch (err) {
throw new Error(`Generating ${feedType} feed failed: ${err}.`);
}