mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
refactor: convert all fs methods to async (#6725)
* refactor: convert all fs methods to async * fix snap
This commit is contained in:
parent
c0b3c9af65
commit
c6d0d812eb
46 changed files with 518 additions and 429 deletions
|
@ -43,8 +43,11 @@ const blogPosts: BlogPost[] = [
|
|||
},
|
||||
];
|
||||
|
||||
const transform = (filePath: string, options?: Partial<LinkifyParams>) => {
|
||||
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
||||
const transform = async (
|
||||
filePath: string,
|
||||
options?: Partial<LinkifyParams>,
|
||||
) => {
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||
const transformedContent = linkify({
|
||||
filePath,
|
||||
fileString: fileContent,
|
||||
|
@ -61,9 +64,9 @@ const transform = (filePath: string, options?: Partial<LinkifyParams>) => {
|
|||
return [fileContent, transformedContent];
|
||||
};
|
||||
|
||||
test('transform to correct link', () => {
|
||||
test('transform to correct link', async () => {
|
||||
const post = path.join(contentPaths.contentPath, 'post.md');
|
||||
const [content, transformedContent] = transform(post);
|
||||
const [content, transformedContent] = await transform(post);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain(
|
||||
'](/blog/2018/12/14/Happy-First-Birthday-Slash',
|
||||
|
@ -74,12 +77,12 @@ test('transform to correct link', () => {
|
|||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('report broken markdown links', () => {
|
||||
test('report broken markdown links', async () => {
|
||||
const filePath = 'post-with-broken-links.md';
|
||||
const folderPath = contentPaths.contentPath;
|
||||
const postWithBrokenLinks = path.join(folderPath, filePath);
|
||||
const onBrokenMarkdownLink = jest.fn();
|
||||
const [, transformedContent] = transform(postWithBrokenLinks, {
|
||||
const [, transformedContent] = await transform(postWithBrokenLinks, {
|
||||
onBrokenMarkdownLink,
|
||||
});
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
|
|
|
@ -332,7 +332,7 @@ export async function generateBlogPosts(
|
|||
): Promise<BlogPost[]> {
|
||||
const {include, exclude} = options;
|
||||
|
||||
if (!fs.existsSync(contentPaths.contentPath)) {
|
||||
if (!(await fs.pathExists(contentPaths.contentPath))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue