mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-24 05:28:01 +02:00
feat(v2): blog + docs multi-instance plugins (#3204)
* stable createData namespacing + second-blog dogfooding * Docs: support multi-instance + make community docs a separate instance * tests: add 2nd docs instance to versioned site * fix docs version cli tests * fix docs versioning cli * typo * team: add link to my site * better extendCli integration * fix metadata tests * tests for versioned site with second docs instance * move some validation code to utils-validation * fix missing dependency * fix bad compiled output due to importing constants in ./client folder * make docs tests easier to maintain * refactors * prevent lodash imports in client bundle * redirect old community docs to new urls
This commit is contained in:
parent
e944f35640
commit
59f705ee66
67 changed files with 2025 additions and 2059 deletions
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* 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 * as Joi from '@hapi/joi';
|
||||
|
||||
import {
|
||||
AdmonitionsSchema,
|
||||
RehypePluginsSchema,
|
||||
RemarkPluginsSchema,
|
||||
PluginIdSchema,
|
||||
} from '../validationSchemas';
|
||||
|
||||
function createTestHelpers({
|
||||
schema,
|
||||
defaultValue,
|
||||
}: {
|
||||
schema: Joi.SchemaLike;
|
||||
defaultValue?: unknown;
|
||||
}) {
|
||||
function testOK(value: unknown) {
|
||||
expect(Joi.attempt(value, schema)).toEqual(value ?? defaultValue);
|
||||
}
|
||||
|
||||
function testFail(value: unknown) {
|
||||
expect(() => Joi.attempt(value, schema)).toThrowErrorMatchingSnapshot(
|
||||
// @ts-expect-error: seems ok at runtime, but bad typedef
|
||||
`for value=${JSON.stringify(value)}`,
|
||||
);
|
||||
}
|
||||
|
||||
return {testOK, testFail};
|
||||
}
|
||||
|
||||
function testMarkdownPluginSchemas(schema: Joi.SchemaLike) {
|
||||
const {testOK, testFail} = createTestHelpers({
|
||||
schema,
|
||||
defaultValue: [],
|
||||
});
|
||||
|
||||
testOK(undefined);
|
||||
testOK([function () {}]);
|
||||
testOK([[function () {}, {attr: 'val'}]]);
|
||||
testOK([
|
||||
[function () {}, {attr: 'val'}],
|
||||
function () {},
|
||||
[function () {}, {attr: 'val'}],
|
||||
]);
|
||||
|
||||
testFail(null);
|
||||
testFail(false);
|
||||
testFail(3);
|
||||
testFail([null]);
|
||||
testFail([false]);
|
||||
testFail([3]);
|
||||
testFail([[]]);
|
||||
testFail([[function () {}, undefined]]);
|
||||
testFail([[function () {}, true]]);
|
||||
}
|
||||
|
||||
describe('validation schemas', () => {
|
||||
test('PluginIdSchema', () => {
|
||||
const {testOK, testFail} = createTestHelpers({
|
||||
schema: PluginIdSchema,
|
||||
defaultValue: 'default',
|
||||
});
|
||||
|
||||
testOK(undefined);
|
||||
testOK('docs');
|
||||
testOK('default');
|
||||
testOK('plugin-id_with-simple-special-chars');
|
||||
|
||||
testFail('/docs');
|
||||
testFail('docs/');
|
||||
testFail('do/cs');
|
||||
testFail('do cs');
|
||||
testFail(null);
|
||||
testFail(3);
|
||||
testFail(true);
|
||||
testFail([]);
|
||||
});
|
||||
|
||||
test('AdmonitionsSchema', () => {
|
||||
const {testOK, testFail} = createTestHelpers({
|
||||
schema: AdmonitionsSchema,
|
||||
defaultValue: {},
|
||||
});
|
||||
|
||||
testOK(undefined);
|
||||
testOK({});
|
||||
testOK({attr: 'val'});
|
||||
|
||||
testFail(null);
|
||||
testFail(3);
|
||||
testFail(true);
|
||||
testFail([]);
|
||||
});
|
||||
|
||||
test('RemarkPluginsSchema', () => {
|
||||
testMarkdownPluginSchemas(RemarkPluginsSchema);
|
||||
});
|
||||
|
||||
test('RehypePluginsSchema', () => {
|
||||
testMarkdownPluginSchemas(RehypePluginsSchema);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue