mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 12:37:01 +02:00
fix(v2): fix too strict markdown frontmatter validation (#4654)
* start work * use orta.vscode-jest * node 14 * add some better infra to validate markdown frontmatter * better docs frontmatter validation * fix Yaml / Joi validation issues * fix Yaml / Joi validation issues Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
c04e613ffe
commit
e11597aba9
8 changed files with 238 additions and 21 deletions
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {
|
||||
BlogPostFrontMatter,
|
||||
validateBlogPostFrontMatter,
|
||||
} from '../blogFrontMatter';
|
||||
|
||||
describe('validateBlogPostFrontMatter', () => {
|
||||
test('accept empty object', () => {
|
||||
const frontMatter = {};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
test('accept valid values', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {
|
||||
id: 'blog',
|
||||
title: 'title',
|
||||
description: 'description',
|
||||
date: 'date',
|
||||
slug: 'slug',
|
||||
draft: true,
|
||||
tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}],
|
||||
};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
test('accept empty title', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {title: ''};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
// See https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
|
||||
test('accept empty description', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {description: ''};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
// See https://github.com/facebook/docusaurus/issues/4642
|
||||
test('convert tags as numbers', () => {
|
||||
const frontMatter: BlogPostFrontMatter = {
|
||||
tags: [
|
||||
// @ts-expect-error: number for test
|
||||
42,
|
||||
{
|
||||
// @ts-expect-error: number for test
|
||||
label: 84,
|
||||
permalink: '/tagPermalink',
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(validateBlogPostFrontMatter(frontMatter)).toEqual({
|
||||
tags: [
|
||||
'42',
|
||||
{
|
||||
label: '84',
|
||||
permalink: '/tagPermalink',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue