mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(v2): modify validation schema and tests for rehype/remark + remove duplicate dependency (#3247)
* chore(v2): remove duplicate dependency * fix(v2): make changes to validation for rehype and remark plugins * style(v2): run prettier
This commit is contained in:
parent
9399ad61c9
commit
fda1590b0d
6 changed files with 63 additions and 42 deletions
|
@ -7,12 +7,14 @@
|
|||
|
||||
import {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema';
|
||||
|
||||
// the type of remark/rehype plugins is function
|
||||
const remarkRehypePluginStub = () => {};
|
||||
// the type of remark/rehype plugins can be either function, object or array
|
||||
const markdownPluginsFunctionStub = () => {};
|
||||
const markdownPluginsObjectStub = {};
|
||||
|
||||
test('should normalize options', () => {
|
||||
const {value} = PluginOptionSchema.validate({});
|
||||
const {value, error} = PluginOptionSchema.validate({});
|
||||
expect(value).toEqual(DEFAULT_OPTIONS);
|
||||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept correctly defined user options', () => {
|
||||
|
@ -24,27 +26,29 @@ test('should accept correctly defined user options', () => {
|
|||
postsPerPage: 5,
|
||||
include: ['api/*', 'docs/*'],
|
||||
};
|
||||
const {value} = PluginOptionSchema.validate(userOptions);
|
||||
const {value, error} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual({
|
||||
...userOptions,
|
||||
feedOptions: {type: ['rss'], title: 'myTitle'},
|
||||
});
|
||||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept valid user options', async () => {
|
||||
const userOptions = {
|
||||
...DEFAULT_OPTIONS,
|
||||
routebasePath: '',
|
||||
routeBasePath: '',
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [remarkRehypePluginStub],
|
||||
remarkPlugins: [remarkRehypePluginStub, {option1: '42'}],
|
||||
beforeDefaultRehypePlugins: [markdownPluginsFunctionStub],
|
||||
remarkPlugins: [[markdownPluginsFunctionStub, {option1: '42'}]],
|
||||
rehypePlugins: [
|
||||
remarkRehypePluginStub,
|
||||
[remarkRehypePluginStub, {option1: '42'}],
|
||||
markdownPluginsObjectStub,
|
||||
[markdownPluginsFunctionStub, {option1: '42'}],
|
||||
],
|
||||
};
|
||||
const {value} = await PluginOptionSchema.validate(userOptions);
|
||||
const {value, error} = await PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should throw Error in case of invalid options', () => {
|
||||
|
|
|
@ -58,22 +58,12 @@ export const PluginOptionSchema = Joi.object({
|
|||
admonitions: AdmonitionsSchema.default(DEFAULT_OPTIONS.admonitions),
|
||||
editUrl: URISchema,
|
||||
truncateMarker: Joi.object().default(DEFAULT_OPTIONS.truncateMarker),
|
||||
beforeDefaultRemarkPlugins: Joi.array()
|
||||
.items(
|
||||
Joi.array()
|
||||
.items(Joi.function().required(), Joi.object().required())
|
||||
.length(2),
|
||||
Joi.function(),
|
||||
)
|
||||
.default(DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
|
||||
beforeDefaultRehypePlugins: Joi.array()
|
||||
.items(
|
||||
Joi.array()
|
||||
.items(Joi.function().required(), Joi.object().required())
|
||||
.length(2),
|
||||
Joi.function(),
|
||||
)
|
||||
.default(DEFAULT_OPTIONS.beforeDefaultRehypePlugins),
|
||||
beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(
|
||||
DEFAULT_OPTIONS.beforeDefaultRemarkPlugins,
|
||||
),
|
||||
beforeDefaultRehypePlugins: RehypePluginsSchema.default(
|
||||
DEFAULT_OPTIONS.beforeDefaultRehypePlugins,
|
||||
),
|
||||
feedOptions: Joi.object({
|
||||
type: Joi.alternatives().conditional(
|
||||
Joi.string().equal('all', 'rss', 'atom'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue