mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-27 13:38:33 +02:00
test(v2): add tests for config validation (#3142)
* test(v2): add tests for correctly defined fields * test(v2): add test for remarkPlugins and rehypePlugins validation * test(v2): modify tests and comments
This commit is contained in:
parent
ee2d1b42f6
commit
e7ec93b0b9
7 changed files with 144 additions and 69 deletions
|
@ -7,28 +7,47 @@
|
|||
|
||||
import {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema';
|
||||
|
||||
test('normalize options', () => {
|
||||
// the type of remark/rehype plugins is function
|
||||
const remarkRehypePluginStub = () => {};
|
||||
|
||||
test('should normalize options', () => {
|
||||
const {value} = PluginOptionSchema.validate({});
|
||||
expect(value).toEqual(DEFAULT_OPTIONS);
|
||||
});
|
||||
|
||||
test('validate options', () => {
|
||||
const {value} = PluginOptionSchema.validate({
|
||||
path: 'not_blog',
|
||||
postsPerPage: 5,
|
||||
include: ['api/*', 'docs/*'],
|
||||
routeBasePath: 'not_blog',
|
||||
});
|
||||
expect(value).toEqual({
|
||||
test('should accept correctly defined user options', () => {
|
||||
const userOptions = {
|
||||
...DEFAULT_OPTIONS,
|
||||
feedOptions: {type: 'rss', title: 'myTitle'},
|
||||
path: 'not_blog',
|
||||
routeBasePath: '',
|
||||
postsPerPage: 5,
|
||||
include: ['api/*', 'docs/*'],
|
||||
routeBasePath: 'not_blog',
|
||||
path: 'not_blog',
|
||||
};
|
||||
const {value} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual({
|
||||
...userOptions,
|
||||
feedOptions: {type: ['rss'], title: 'myTitle'},
|
||||
});
|
||||
});
|
||||
|
||||
test('throw Error in case of invalid options', () => {
|
||||
test('should accept valid user options', async () => {
|
||||
const userOptions = {
|
||||
...DEFAULT_OPTIONS,
|
||||
routebasePath: '',
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [remarkRehypePluginStub],
|
||||
remarkPlugins: [remarkRehypePluginStub, {option1: '42'}],
|
||||
rehypePlugins: [
|
||||
remarkRehypePluginStub,
|
||||
[remarkRehypePluginStub, {option1: '42'}],
|
||||
],
|
||||
};
|
||||
const {value} = await PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
});
|
||||
|
||||
test('should throw Error in case of invalid options', () => {
|
||||
const {error} = PluginOptionSchema.validate({
|
||||
path: 'not_blog',
|
||||
postsPerPage: -1,
|
||||
|
@ -39,7 +58,7 @@ test('throw Error in case of invalid options', () => {
|
|||
expect(error).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('throw Error in case of invalid feedtype', () => {
|
||||
test('should throw Error in case of invalid feedtype', () => {
|
||||
const {error} = PluginOptionSchema.validate({
|
||||
feedOptions: {
|
||||
type: 'none',
|
||||
|
@ -49,7 +68,7 @@ test('throw Error in case of invalid feedtype', () => {
|
|||
expect(error).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('convert all feed type to array with other feed type', () => {
|
||||
test('should convert all feed type to array with other feed type', () => {
|
||||
const {value} = PluginOptionSchema.validate({
|
||||
feedOptions: {type: 'all'},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue