polish(v2): url-subpath config validation warning (#4977)

This commit is contained in:
Sébastien Lorber 2021-06-15 18:18:12 +02:00 committed by GitHub
parent dfe32dac9e
commit 9fe79caadc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 5 deletions

View file

@ -5,7 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/
import {DEFAULT_CONFIG, validateConfig} from '../configValidation';
import {
ConfigSchema,
DEFAULT_CONFIG,
validateConfig,
} from '../configValidation';
import {DocusaurusConfig} from '@docusaurus/types';
const baseConfig = {
@ -197,3 +201,26 @@ describe('normalizeConfig', () => {
).toThrowErrorMatchingSnapshot();
});
});
describe('config warnings', () => {
function getWarning(config: unknown) {
return ConfigSchema.validate(config).warning;
}
test('baseConfig has no warning', () => {
const warning = getWarning(baseConfig);
expect(warning).toBeUndefined();
});
test('site url has warning when using subpath', () => {
const warning = getWarning({
...baseConfig,
url: 'https://mysite.com/someSubpath',
});
expect(warning).toBeDefined();
expect(warning?.details.length).toEqual(1);
expect(warning?.details[0].message).toMatchInlineSnapshot(
`"Docusaurus config validation warning. Field \\"url\\": the url is not supposed to contain a sub-path like '/someSubpath', please use the baseUrl field for sub-paths"`,
);
});
});