mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-29 08:57:03 +02:00
test(v2): make blog posts unit test ordering determinate (#3339)
This commit is contained in:
parent
8fd5375b26
commit
3ccca399f1
3 changed files with 38 additions and 31 deletions
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
slug: /simple/slug
|
||||
title: Simple Slug
|
||||
date: 2020-08-16
|
||||
date: 2020-08-15
|
||||
---
|
||||
|
||||
simple url slug
|
||||
|
|
|
@ -21,9 +21,8 @@ function validateAndNormalize(schema, options) {
|
|||
}
|
||||
|
||||
describe('loadBlog', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const pluginPath = 'blog';
|
||||
const getBlogPosts = async () => {
|
||||
const getBlogPosts = async (siteDir) => {
|
||||
const generatedFilesDir: string = path.resolve(siteDir, '.docusaurus');
|
||||
const siteConfig = {
|
||||
title: 'Hello',
|
||||
|
@ -48,11 +47,8 @@ describe('loadBlog', () => {
|
|||
};
|
||||
|
||||
test('simple website', async () => {
|
||||
const blogPosts = await getBlogPosts();
|
||||
const noDateSource = path.join('@site', pluginPath, 'no date.md');
|
||||
const noDateSourceBirthTime = (
|
||||
await fs.stat(noDateSource.replace('@site', siteDir))
|
||||
).birthtime;
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const blogPosts = await getBlogPosts(siteDir);
|
||||
|
||||
expect({
|
||||
...blogPosts.find((v) => v.metadata.title === 'date-matter').metadata,
|
||||
|
@ -99,27 +95,6 @@ describe('loadBlog', () => {
|
|||
truncated: false,
|
||||
});
|
||||
|
||||
expect({
|
||||
...blogPosts.find((v) => v.metadata.title === 'no date').metadata,
|
||||
...{prevItem: undefined},
|
||||
}).toEqual({
|
||||
editUrl:
|
||||
'https://github.com/facebook/docusaurus/edit/master/website-1x/blog/no date.md',
|
||||
permalink: '/blog/no date',
|
||||
readingTime: 0.01,
|
||||
source: noDateSource,
|
||||
title: 'no date',
|
||||
description: `no date`,
|
||||
date: noDateSourceBirthTime,
|
||||
tags: [],
|
||||
prevItem: undefined,
|
||||
nextItem: {
|
||||
permalink: '/blog/hey/my super path/héllô',
|
||||
title: 'Complex Slug',
|
||||
},
|
||||
truncated: false,
|
||||
});
|
||||
|
||||
expect({
|
||||
...blogPosts.find((v) => v.metadata.title === 'Complex Slug').metadata,
|
||||
...{prevItem: undefined},
|
||||
|
@ -157,7 +132,7 @@ describe('loadBlog', () => {
|
|||
permalink: '/blog/draft',
|
||||
title: 'draft',
|
||||
},
|
||||
date: new Date('2020-08-16'),
|
||||
date: new Date('2020-08-15'),
|
||||
tags: [],
|
||||
truncated: false,
|
||||
});
|
||||
|
@ -165,8 +140,40 @@ describe('loadBlog', () => {
|
|||
|
||||
test('draft blog post not exists in production build', async () => {
|
||||
process.env.NODE_ENV = 'production';
|
||||
const blogPosts = await getBlogPosts();
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const blogPosts = await getBlogPosts(siteDir);
|
||||
|
||||
expect(blogPosts.find((v) => v.metadata.title === 'draft')).toBeUndefined();
|
||||
});
|
||||
|
||||
test('create blog post without date', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
'website-blog-without-date',
|
||||
);
|
||||
const blogPosts = await getBlogPosts(siteDir);
|
||||
const noDateSource = path.join('@site', pluginPath, 'no date.md');
|
||||
const noDateSourceBirthTime = (
|
||||
await fs.stat(noDateSource.replace('@site', siteDir))
|
||||
).birthtime;
|
||||
|
||||
expect({
|
||||
...blogPosts.find((v) => v.metadata.title === 'no date').metadata,
|
||||
...{prevItem: undefined},
|
||||
}).toEqual({
|
||||
editUrl:
|
||||
'https://github.com/facebook/docusaurus/edit/master/website-1x/blog/no date.md',
|
||||
permalink: '/blog/no date',
|
||||
readingTime: 0.01,
|
||||
source: noDateSource,
|
||||
title: 'no date',
|
||||
description: `no date`,
|
||||
date: noDateSourceBirthTime,
|
||||
tags: [],
|
||||
prevItem: undefined,
|
||||
nextItem: undefined,
|
||||
truncated: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue