mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
test(utils, mdx-loader, core): improve coverage (#6303)
* test(utils, mdx-loader, core): improve coverage * windows... * fix
This commit is contained in:
parent
cf265c051e
commit
a79c23bc45
38 changed files with 841 additions and 219 deletions
|
@ -8,6 +8,10 @@ exports[`validation schemas AdmonitionsSchema: for value=null 1`] = `"\\"value\\
|
|||
|
||||
exports[`validation schemas AdmonitionsSchema: for value=true 1`] = `"\\"value\\" must be of type object"`;
|
||||
|
||||
exports[`validation schemas PathnameSchema: for value="foo" 1`] = `"\\"value\\" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
||||
exports[`validation schemas PathnameSchema: for value="https://github.com/foo" 1`] = `"\\"value\\" is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;
|
||||
|
||||
exports[`validation schemas PluginIdSchema: for value="/docs" 1`] = `"\\"value\\" with value \\"/docs\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
|
||||
|
||||
exports[`validation schemas PluginIdSchema: for value="do cs" 1`] = `"\\"value\\" with value \\"do cs\\" fails to match the required pattern: /^[a-zA-Z_-]+$/"`;
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
RemarkPluginsSchema,
|
||||
PluginIdSchema,
|
||||
URISchema,
|
||||
PathnameSchema,
|
||||
} from '../validationSchemas';
|
||||
|
||||
function createTestHelpers({
|
||||
|
@ -128,4 +129,12 @@ describe('validation schemas', () => {
|
|||
testOK(protocolRelativeUrl1);
|
||||
testOK(protocolRelativeUrl2);
|
||||
});
|
||||
|
||||
test('PathnameSchema', () => {
|
||||
const {testFail, testOK} = createTestHelpers({schema: PathnameSchema});
|
||||
|
||||
testOK('/foo');
|
||||
testFail('foo');
|
||||
testFail('https://github.com/foo');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,6 +36,17 @@ describe('validateFrontMatter', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should not convert simple values', () => {
|
||||
const schema = Joi.object({
|
||||
test: JoiFrontMatter.string(),
|
||||
});
|
||||
const frontMatter = {
|
||||
test: 'foo',
|
||||
tags: ['foo', 'bar'],
|
||||
};
|
||||
expect(validateFrontMatter(frontMatter, schema)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
// Fix Yaml trying to convert strings to numbers automatically
|
||||
// We only want to deal with a single type in the final frontmatter (not string | number)
|
||||
test('should convert number values to string when string schema', () => {
|
||||
|
|
|
@ -34,12 +34,9 @@ export const URISchema = Joi.alternatives(
|
|||
// This custom validation logic is required notably because Joi does not accept paths like /a/b/c ...
|
||||
Joi.custom((val, helpers) => {
|
||||
try {
|
||||
const url = new URL(val);
|
||||
if (url) {
|
||||
return val;
|
||||
} else {
|
||||
return helpers.error('any.invalid');
|
||||
}
|
||||
// eslint-disable-next-line no-new
|
||||
new URL(val);
|
||||
return val;
|
||||
} catch {
|
||||
return helpers.error('any.invalid');
|
||||
}
|
||||
|
@ -53,9 +50,8 @@ export const PathnameSchema = Joi.string()
|
|||
.custom((val) => {
|
||||
if (!isValidPathname(val)) {
|
||||
throw new Error();
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
return val;
|
||||
})
|
||||
.message(
|
||||
'{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue