mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
test(theme-common): improve test coverage (#6902)
* test(theme-common): improve test coverage * revert
This commit is contained in:
parent
aa5a2d4c04
commit
f6baaa6b75
59 changed files with 1183 additions and 755 deletions
|
@ -211,8 +211,12 @@ module.exports = {
|
|||
WARNING,
|
||||
{maxSize: Infinity, inlineMaxSize: 10},
|
||||
],
|
||||
'jest/no-test-return-statement': ERROR,
|
||||
'jest/prefer-expect-resolves': WARNING,
|
||||
'jest/prefer-lowercase-title': [WARNING, {ignore: ['describe']}],
|
||||
'jest/prefer-spy-on': WARNING,
|
||||
'jest/prefer-to-be': WARNING,
|
||||
'jest/prefer-to-have-length': WARNING,
|
||||
'jest/require-top-level-describe': ERROR,
|
||||
'jest/valid-title': [
|
||||
ERROR,
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
"@babel/core": "^7.17.5",
|
||||
"@babel/preset-typescript": "^7.16.7",
|
||||
"@crowdin/cli": "^3.7.8",
|
||||
"@testing-library/react-hooks": "^7.0.2",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/lodash": "^4.14.179",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`migration test complex website: copy 1`] = `
|
||||
exports[`migration CLI migrates complex website: copy 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/complex_website/website/blog",
|
||||
|
@ -17,7 +17,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test complex website: mkdirp 1`] = `
|
||||
exports[`migration CLI migrates complex website: mkdirp 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_complex_site/src/pages",
|
||||
|
@ -25,9 +25,9 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test complex website: mkdirs 1`] = `Array []`;
|
||||
exports[`migration CLI migrates complex website: mkdirs 1`] = `Array []`;
|
||||
|
||||
exports[`migration test complex website: write 1`] = `
|
||||
exports[`migration CLI migrates complex website: write 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_complex_site/docusaurus.config.js",
|
||||
|
@ -183,7 +183,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test missing versions: copy 1`] = `
|
||||
exports[`migration CLI migrates missing versions: copy 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/missing_version_website/website/blog",
|
||||
|
@ -200,7 +200,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test missing versions: mkdirp 1`] = `
|
||||
exports[`migration CLI migrates missing versions: mkdirp 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_missing_version_site/src/pages",
|
||||
|
@ -208,9 +208,9 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test missing versions: mkdirs 1`] = `Array []`;
|
||||
exports[`migration CLI migrates missing versions: mkdirs 1`] = `Array []`;
|
||||
|
||||
exports[`migration test missing versions: write 1`] = `
|
||||
exports[`migration CLI migrates missing versions: write 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_missing_version_site/docusaurus.config.js",
|
||||
|
@ -366,7 +366,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test simple website: copy 1`] = `
|
||||
exports[`migration CLI migrates simple website: copy 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/simple_website/website/pages/en",
|
||||
|
@ -379,7 +379,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test simple website: mkdirp 1`] = `
|
||||
exports[`migration CLI migrates simple website: mkdirp 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_simple_site/src/pages",
|
||||
|
@ -387,9 +387,9 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`migration test simple website: mkdirs 1`] = `Array []`;
|
||||
exports[`migration CLI migrates simple website: mkdirs 1`] = `Array []`;
|
||||
|
||||
exports[`migration test simple website: write 1`] = `
|
||||
exports[`migration CLI migrates simple website: write 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
"<PROJECT_ROOT>/packages/docusaurus-migrate/src/__tests__/__fixtures__/migrated_simple_site/docusaurus.config.js",
|
|
@ -9,19 +9,19 @@ import {shouldQuotifyFrontMatter} from '../frontMatter';
|
|||
|
||||
describe('shouldQuotifyFrontMatter', () => {
|
||||
it('works', () => {
|
||||
expect(shouldQuotifyFrontMatter(['id', 'value'])).toEqual(false);
|
||||
expect(shouldQuotifyFrontMatter(['id', 'value'])).toBe(false);
|
||||
expect(
|
||||
shouldQuotifyFrontMatter([
|
||||
'title',
|
||||
"Some title front matter with allowed special chars like sàáâãäåçèéêëìíîïðòóôõöùúûüýÿ!;,=+-_?'`&#()[]§%€$",
|
||||
]),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
|
||||
expect(shouldQuotifyFrontMatter(['title', 'Special char :'])).toEqual(true);
|
||||
expect(shouldQuotifyFrontMatter(['title', 'Special char :'])).toBe(true);
|
||||
|
||||
expect(shouldQuotifyFrontMatter(['title', 'value!'])).toEqual(false);
|
||||
expect(shouldQuotifyFrontMatter(['title', '!value'])).toEqual(true);
|
||||
expect(shouldQuotifyFrontMatter(['title', 'value!'])).toBe(false);
|
||||
expect(shouldQuotifyFrontMatter(['title', '!value'])).toBe(true);
|
||||
|
||||
expect(shouldQuotifyFrontMatter(['tags', '[tag1, tag2]'])).toEqual(false);
|
||||
expect(shouldQuotifyFrontMatter(['tags', '[tag1, tag2]'])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -43,20 +43,21 @@ async function testMigration(siteDir: string, newDir: string) {
|
|||
copyMock.mockRestore();
|
||||
}
|
||||
|
||||
describe('migration test', () => {
|
||||
describe('migration CLI', () => {
|
||||
const fixtureDir = path.join(__dirname, '__fixtures__');
|
||||
it('simple website', async () => {
|
||||
it('migrates simple website', async () => {
|
||||
const siteDir = path.join(fixtureDir, 'simple_website', 'website');
|
||||
const newDir = path.join(fixtureDir, 'migrated_simple_site');
|
||||
await testMigration(siteDir, newDir);
|
||||
});
|
||||
it('complex website', async () => {
|
||||
|
||||
it('migrates complex website', async () => {
|
||||
const siteDir = path.join(fixtureDir, 'complex_website', 'website');
|
||||
const newDir = path.join(fixtureDir, 'migrated_complex_site');
|
||||
await testMigration(siteDir, newDir);
|
||||
});
|
||||
|
||||
it('missing versions', async () => {
|
||||
it('migrates missing versions', async () => {
|
||||
const siteDir = path.join(fixtureDir, 'missing_version_website', 'website');
|
||||
const newDir = path.join(fixtureDir, 'migrated_missing_version_site');
|
||||
await testMigration(siteDir, newDir);
|
|
@ -35,14 +35,8 @@ declare module '@generated/registry' {
|
|||
}
|
||||
|
||||
declare module '@generated/routes' {
|
||||
import type {RouteConfig} from 'react-router-config';
|
||||
import type {Route} from '@docusaurus/types';
|
||||
|
||||
export type Route = {
|
||||
readonly path: string;
|
||||
readonly component: RouteConfig['component'];
|
||||
readonly exact?: boolean;
|
||||
readonly routes?: Route[];
|
||||
};
|
||||
const routes: Route[];
|
||||
export default routes;
|
||||
}
|
||||
|
|
|
@ -18,25 +18,25 @@ import writeRedirectFiles, {
|
|||
// - https://github.com/facebook/docusaurus/issues/3925
|
||||
describe('createToUrl', () => {
|
||||
it('creates appropriate redirect urls', async () => {
|
||||
expect(createToUrl('/', '/docs/something/else')).toEqual(
|
||||
expect(createToUrl('/', '/docs/something/else')).toBe(
|
||||
'/docs/something/else',
|
||||
);
|
||||
expect(createToUrl('/', '/docs/something/else/')).toEqual(
|
||||
expect(createToUrl('/', '/docs/something/else/')).toBe(
|
||||
'/docs/something/else/',
|
||||
);
|
||||
expect(createToUrl('/', 'docs/something/else')).toEqual(
|
||||
expect(createToUrl('/', 'docs/something/else')).toBe(
|
||||
'/docs/something/else',
|
||||
);
|
||||
});
|
||||
|
||||
it('creates appropriate redirect urls with baseUrl', async () => {
|
||||
expect(createToUrl('/baseUrl/', '/docs/something/else')).toEqual(
|
||||
expect(createToUrl('/baseUrl/', '/docs/something/else')).toBe(
|
||||
'/baseUrl/docs/something/else',
|
||||
);
|
||||
expect(createToUrl('/baseUrl/', '/docs/something/else/')).toEqual(
|
||||
expect(createToUrl('/baseUrl/', '/docs/something/else/')).toBe(
|
||||
'/baseUrl/docs/something/else/',
|
||||
);
|
||||
expect(createToUrl('/baseUrl/', 'docs/something/else')).toEqual(
|
||||
expect(createToUrl('/baseUrl/', 'docs/something/else')).toBe(
|
||||
'/baseUrl/docs/something/else',
|
||||
);
|
||||
});
|
||||
|
@ -177,11 +177,11 @@ describe('writeRedirectFiles', () => {
|
|||
|
||||
await expect(
|
||||
fs.readFile(filesMetadata[0].fileAbsolutePath, 'utf8'),
|
||||
).resolves.toEqual('content 1');
|
||||
).resolves.toBe('content 1');
|
||||
|
||||
await expect(
|
||||
fs.readFile(filesMetadata[1].fileAbsolutePath, 'utf8'),
|
||||
).resolves.toEqual('content 2');
|
||||
).resolves.toBe('content 2');
|
||||
});
|
||||
|
||||
it('avoid overwriting existing files', async () => {
|
||||
|
|
|
@ -75,17 +75,17 @@ describe('truncate', () => {
|
|||
it('truncates texts', () => {
|
||||
expect(
|
||||
truncate('aaa\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/),
|
||||
).toEqual('aaa\n');
|
||||
expect(
|
||||
truncate('\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/),
|
||||
).toEqual('\n');
|
||||
).toBe('aaa\n');
|
||||
expect(truncate('\n<!-- truncate -->\nbbb\nccc', /<!-- truncate -->/)).toBe(
|
||||
'\n',
|
||||
);
|
||||
});
|
||||
|
||||
it('leaves texts without markers', () => {
|
||||
expect(truncate('aaa\nbbb\nccc', /<!-- truncate -->/)).toEqual(
|
||||
expect(truncate('aaa\nbbb\nccc', /<!-- truncate -->/)).toBe(
|
||||
'aaa\nbbb\nccc',
|
||||
);
|
||||
expect(truncate('', /<!-- truncate -->/)).toEqual('');
|
||||
expect(truncate('', /<!-- truncate -->/)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -341,7 +341,7 @@ describe('blog plugin', () => {
|
|||
(v) => v.metadata.title === 'Happy 1st Birthday Slash! (translated)',
|
||||
)!;
|
||||
|
||||
expect(localizedBlogPost.metadata.editUrl).toEqual(
|
||||
expect(localizedBlogPost.metadata.editUrl).toBe(
|
||||
`${BaseEditUrl}/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md`,
|
||||
);
|
||||
});
|
||||
|
@ -478,7 +478,7 @@ describe('blog plugin', () => {
|
|||
postsPerPage: 2,
|
||||
});
|
||||
|
||||
expect(Object.keys(blogTags).length).toEqual(2);
|
||||
expect(Object.keys(blogTags)).toHaveLength(2);
|
||||
expect(blogTags).toMatchSnapshot();
|
||||
});
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('blog plugin options schema', () => {
|
|||
it('normalizes options', () => {
|
||||
const {value, error} = PluginOptionSchema.validate({});
|
||||
expect(value).toEqual(DEFAULT_OPTIONS);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts correctly defined user options', () => {
|
||||
|
@ -32,7 +32,7 @@ describe('blog plugin options schema', () => {
|
|||
...userOptions,
|
||||
feedOptions: {type: ['rss'], title: 'myTitle', copyright: ''},
|
||||
});
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts valid user options', async () => {
|
||||
|
@ -49,7 +49,7 @@ describe('blog plugin options schema', () => {
|
|||
};
|
||||
const {value, error} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('throws Error in case of invalid options', () => {
|
||||
|
@ -91,7 +91,7 @@ describe('blog plugin options schema', () => {
|
|||
...DEFAULT_OPTIONS,
|
||||
feedOptions: {type: null},
|
||||
});
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('contains array with rss + atom for missing feed type', () => {
|
||||
|
@ -117,14 +117,14 @@ describe('blog sidebar', () => {
|
|||
const userOptions = {blogSidebarCount: 0};
|
||||
const {value, error} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts "ALL" sidebar count', () => {
|
||||
const userOptions = {blogSidebarCount: 'ALL'};
|
||||
const {value, error} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects "abcdef" sidebar count', () => {
|
||||
|
@ -139,7 +139,7 @@ describe('blog sidebar', () => {
|
|||
const userOptions = {blogSidebarTitle: 'all posts'};
|
||||
const {value, error} = PluginOptionSchema.validate(userOptions);
|
||||
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('rejects 42 sidebar title', () => {
|
||||
|
|
|
@ -16,6 +16,29 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`sidebar site with wrong sidebar content 1`] = `
|
||||
"Invalid sidebar file at \\"packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json\\".
|
||||
These sidebar document ids do not exist:
|
||||
- goku
|
||||
|
||||
Available document ids are:
|
||||
- doc with space
|
||||
- foo/bar
|
||||
- foo/baz
|
||||
- headingAsTitle
|
||||
- hello
|
||||
- ipsum
|
||||
- lorem
|
||||
- rootAbsoluteSlug
|
||||
- rootRelativeSlug
|
||||
- rootResolvedSlug
|
||||
- rootTryToEscapeSlug
|
||||
- slugs/absoluteSlug
|
||||
- slugs/relativeSlug
|
||||
- slugs/resolvedSlug
|
||||
- slugs/tryToEscapeSlug"
|
||||
`;
|
||||
|
||||
exports[`simple website content 1`] = `
|
||||
Object {
|
||||
"description": "Images",
|
||||
|
|
|
@ -176,7 +176,7 @@ describe('simple site', () => {
|
|||
context,
|
||||
options,
|
||||
});
|
||||
expect(versionsMetadata.length).toEqual(1);
|
||||
expect(versionsMetadata).toHaveLength(1);
|
||||
const [currentVersion] = versionsMetadata;
|
||||
|
||||
const defaultTestUtils = createTestUtils({
|
||||
|
@ -533,7 +533,7 @@ describe('versioned site', () => {
|
|||
context,
|
||||
options,
|
||||
});
|
||||
expect(versionsMetadata.length).toEqual(4);
|
||||
expect(versionsMetadata).toHaveLength(4);
|
||||
const [currentVersion, version101, version100, versionWithSlugs] =
|
||||
versionsMetadata;
|
||||
|
||||
|
@ -947,28 +947,28 @@ describe('isConventionalDocIndex', () => {
|
|||
directories: ['doesNotMatter'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'readme',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'README',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'ReAdMe',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('supports index', () => {
|
||||
|
@ -978,28 +978,28 @@ describe('isConventionalDocIndex', () => {
|
|||
directories: ['doesNotMatter'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'index',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'INDEX',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'InDeX',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('supports <categoryName>/<categoryName>.md', () => {
|
||||
|
@ -1009,35 +1009,35 @@ describe('isConventionalDocIndex', () => {
|
|||
directories: ['someCategory', 'doesNotMatter'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'someCategory',
|
||||
directories: ['someCategory'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'someCategory',
|
||||
directories: ['someCategory'],
|
||||
extension: '.mdx',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'SOME_CATEGORY',
|
||||
directories: ['some_category'],
|
||||
extension: '.md',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'some_category',
|
||||
directories: ['some_category'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('reject other cases', () => {
|
||||
|
@ -1047,20 +1047,20 @@ describe('isConventionalDocIndex', () => {
|
|||
directories: ['someCategory'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'read_me',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'the index',
|
||||
directories: ['doesNotMatter'],
|
||||
extension: '',
|
||||
}),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -123,29 +123,7 @@ describe('sidebar', () => {
|
|||
sidebarPath,
|
||||
}),
|
||||
);
|
||||
await expect(plugin.loadContent!()).rejects
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"Invalid sidebar file at \\"packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json\\".
|
||||
These sidebar document ids do not exist:
|
||||
- goku
|
||||
|
||||
Available document ids are:
|
||||
- doc with space
|
||||
- foo/bar
|
||||
- foo/baz
|
||||
- headingAsTitle
|
||||
- hello
|
||||
- ipsum
|
||||
- lorem
|
||||
- rootAbsoluteSlug
|
||||
- rootRelativeSlug
|
||||
- rootResolvedSlug
|
||||
- rootTryToEscapeSlug
|
||||
- slugs/absoluteSlug
|
||||
- slugs/relativeSlug
|
||||
- slugs/resolvedSlug
|
||||
- slugs/tryToEscapeSlug"
|
||||
`);
|
||||
await expect(plugin.loadContent!()).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
it('site with wrong sidebar file path', async () => {
|
||||
|
@ -281,17 +259,17 @@ describe('simple website', () => {
|
|||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).toMatchSnapshot();
|
||||
expect(isMatch('docs/hello.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('docs/hello.mdx', matchPattern)).toEqual(true);
|
||||
expect(isMatch('docs/foo/bar.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('docs/hello.js', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/super.mdl', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/mdx', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/headingAsTitle.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('sidebars.json', matchPattern)).toEqual(true);
|
||||
expect(isMatch('versioned_docs/hello.md', matchPattern)).toEqual(false);
|
||||
expect(isMatch('hello.md', matchPattern)).toEqual(false);
|
||||
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/hello.md', matchPattern)).toBe(true);
|
||||
expect(isMatch('docs/hello.mdx', matchPattern)).toBe(true);
|
||||
expect(isMatch('docs/foo/bar.md', matchPattern)).toBe(true);
|
||||
expect(isMatch('docs/hello.js', matchPattern)).toBe(false);
|
||||
expect(isMatch('docs/super.mdl', matchPattern)).toBe(false);
|
||||
expect(isMatch('docs/mdx', matchPattern)).toBe(false);
|
||||
expect(isMatch('docs/headingAsTitle.md', matchPattern)).toBe(true);
|
||||
expect(isMatch('sidebars.json', matchPattern)).toBe(true);
|
||||
expect(isMatch('versioned_docs/hello.md', matchPattern)).toBe(false);
|
||||
expect(isMatch('hello.md', matchPattern)).toBe(false);
|
||||
expect(isMatch('super/docs/hello.md', matchPattern)).toBe(false);
|
||||
});
|
||||
|
||||
it('configureWebpack', async () => {
|
||||
|
@ -319,7 +297,7 @@ describe('simple website', () => {
|
|||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(1);
|
||||
expect(content.loadedVersions).toHaveLength(1);
|
||||
const [currentVersion] = content.loadedVersions;
|
||||
|
||||
expect(findDocById(currentVersion, 'foo/baz')).toMatchSnapshot();
|
||||
|
@ -398,42 +376,42 @@ describe('versioned website', () => {
|
|||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
expect(matchPattern).toMatchSnapshot();
|
||||
expect(isMatch('docs/hello.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('docs/hello.mdx', matchPattern)).toEqual(true);
|
||||
expect(isMatch('docs/foo/bar.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('sidebars.json', matchPattern)).toEqual(true);
|
||||
expect(
|
||||
isMatch('versioned_docs/version-1.0.0/hello.md', matchPattern),
|
||||
).toEqual(true);
|
||||
expect(isMatch('docs/hello.md', matchPattern)).toBe(true);
|
||||
expect(isMatch('docs/hello.mdx', matchPattern)).toBe(true);
|
||||
expect(isMatch('docs/foo/bar.md', matchPattern)).toBe(true);
|
||||
expect(isMatch('sidebars.json', matchPattern)).toBe(true);
|
||||
expect(isMatch('versioned_docs/version-1.0.0/hello.md', matchPattern)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
isMatch('versioned_docs/version-1.0.0/foo/bar.md', matchPattern),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
isMatch('versioned_sidebars/version-1.0.0-sidebars.json', matchPattern),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
|
||||
// Non existing version
|
||||
expect(
|
||||
isMatch('versioned_docs/version-2.0.0/foo/bar.md', matchPattern),
|
||||
).toEqual(false);
|
||||
expect(
|
||||
isMatch('versioned_docs/version-2.0.0/hello.md', matchPattern),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(isMatch('versioned_docs/version-2.0.0/hello.md', matchPattern)).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
isMatch('versioned_sidebars/version-2.0.0-sidebars.json', matchPattern),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
|
||||
expect(isMatch('docs/hello.js', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/super.mdl', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/mdx', matchPattern)).toEqual(false);
|
||||
expect(isMatch('hello.md', matchPattern)).toEqual(false);
|
||||
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
|
||||
expect(isMatch('docs/hello.js', matchPattern)).toBe(false);
|
||||
expect(isMatch('docs/super.mdl', matchPattern)).toBe(false);
|
||||
expect(isMatch('docs/mdx', matchPattern)).toBe(false);
|
||||
expect(isMatch('hello.md', matchPattern)).toBe(false);
|
||||
expect(isMatch('super/docs/hello.md', matchPattern)).toBe(false);
|
||||
});
|
||||
|
||||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(4);
|
||||
expect(content.loadedVersions).toHaveLength(4);
|
||||
const [currentVersion, version101, version100, versionWithSlugs] =
|
||||
content.loadedVersions;
|
||||
|
||||
|
@ -529,32 +507,32 @@ describe('versioned website (community)', () => {
|
|||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
expect(matchPattern).toMatchSnapshot();
|
||||
expect(isMatch('community/team.md', matchPattern)).toEqual(true);
|
||||
expect(isMatch('community/team.md', matchPattern)).toBe(true);
|
||||
expect(
|
||||
isMatch('community_versioned_docs/version-1.0.0/team.md', matchPattern),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
|
||||
// Non existing version
|
||||
expect(
|
||||
isMatch('community_versioned_docs/version-2.0.0/team.md', matchPattern),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(
|
||||
isMatch(
|
||||
'community_versioned_sidebars/version-2.0.0-sidebars.json',
|
||||
matchPattern,
|
||||
),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
|
||||
expect(isMatch('community/team.js', matchPattern)).toEqual(false);
|
||||
expect(isMatch('community/team.js', matchPattern)).toBe(false);
|
||||
expect(
|
||||
isMatch('community_versioned_docs/version-1.0.0/team.js', matchPattern),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(2);
|
||||
expect(content.loadedVersions).toHaveLength(2);
|
||||
const [currentVersion, version100] = content.loadedVersions;
|
||||
|
||||
expect(getDocById(currentVersion, 'team')).toMatchSnapshot();
|
||||
|
@ -600,7 +578,7 @@ describe('site with doc label', () => {
|
|||
const loadedVersion = content.loadedVersions[0];
|
||||
const sidebarProps = toSidebarsProp(loadedVersion);
|
||||
|
||||
expect(sidebarProps.docs[0].label).toEqual('Hello One');
|
||||
expect(sidebarProps.docs[0].label).toBe('Hello One');
|
||||
});
|
||||
|
||||
it('sidebar_label in doc has higher precedence over label in sidebar.json', async () => {
|
||||
|
@ -608,7 +586,7 @@ describe('site with doc label', () => {
|
|||
const loadedVersion = content.loadedVersions[0];
|
||||
const sidebarProps = toSidebarsProp(loadedVersion);
|
||||
|
||||
expect(sidebarProps.docs[1].label).toEqual('Hello 2 From Doc');
|
||||
expect(sidebarProps.docs[1].label).toBe('Hello 2 From Doc');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -70,45 +70,37 @@ describe('stripNumberPrefix', () => {
|
|||
}
|
||||
|
||||
it('strips number prefix if present', () => {
|
||||
expect(stripNumberPrefixDefault('1-My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('01-My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001-My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 - My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 - My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 - My Doc')).toEqual(
|
||||
expect(stripNumberPrefixDefault('1-My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('01-My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001-My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 - My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 - My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 - My Doc')).toBe('My Doc');
|
||||
//
|
||||
expect(stripNumberPrefixDefault('1---My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('01---My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001---My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 --- My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 --- My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 --- My Doc')).toBe(
|
||||
'My Doc',
|
||||
);
|
||||
//
|
||||
expect(stripNumberPrefixDefault('1---My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('01---My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001---My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 --- My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 --- My Doc')).toEqual(
|
||||
'My Doc',
|
||||
);
|
||||
expect(stripNumberPrefixDefault('999 --- My Doc')).toEqual(
|
||||
expect(stripNumberPrefixDefault('1___My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('01___My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001___My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 ___ My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 ___ My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 ___ My Doc')).toBe(
|
||||
'My Doc',
|
||||
);
|
||||
//
|
||||
expect(stripNumberPrefixDefault('1___My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('01___My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001___My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 ___ My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 ___ My Doc')).toEqual(
|
||||
'My Doc',
|
||||
);
|
||||
expect(stripNumberPrefixDefault('999 ___ My Doc')).toEqual(
|
||||
'My Doc',
|
||||
);
|
||||
//
|
||||
expect(stripNumberPrefixDefault('1.My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('01.My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001.My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 . My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 . My Doc')).toEqual('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 . My Doc')).toEqual(
|
||||
'My Doc',
|
||||
);
|
||||
expect(stripNumberPrefixDefault('1.My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('01.My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001.My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 . My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('001 . My Doc')).toBe('My Doc');
|
||||
expect(stripNumberPrefixDefault('999 . My Doc')).toBe('My Doc');
|
||||
});
|
||||
|
||||
it('does not strip number prefix if pattern does not match', () => {
|
||||
|
@ -125,7 +117,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
||||
DefaultNumberPrefixParser,
|
||||
),
|
||||
).toEqual('MyRootFolder0/MySubFolder1/MyDeepFolder2/MyDoc3');
|
||||
).toBe('MyRootFolder0/MySubFolder1/MyDeepFolder2/MyDoc3');
|
||||
});
|
||||
|
||||
it('strips number prefixes in paths with custom parser', () => {
|
||||
|
@ -138,7 +130,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
|
||||
expect(
|
||||
stripPathNumberPrefixes('aaaa/bbbb/cccc', stripPathNumberPrefixCustom),
|
||||
).toEqual('aaa/bbb/ccc');
|
||||
).toBe('aaa/bbb/ccc');
|
||||
});
|
||||
|
||||
it('does not strip number prefixes in paths with disabled parser', () => {
|
||||
|
@ -147,7 +139,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
||||
DisabledNumberPrefixParser,
|
||||
),
|
||||
).toEqual('0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3');
|
||||
).toBe('0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
it('returns default options for undefined user options', async () => {
|
||||
const {value, error} = await OptionsSchema.validate({});
|
||||
expect(value).toEqual(DEFAULT_OPTIONS);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts correctly defined user options', async () => {
|
||||
|
@ -79,7 +79,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
};
|
||||
const {value, error} = await OptionsSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts correctly defined remark and rehype plugin options', async () => {
|
||||
|
@ -95,7 +95,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
};
|
||||
const {value, error} = await OptionsSchema.validate(userOptions);
|
||||
expect(value).toEqual(userOptions);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts admonitions false', async () => {
|
||||
|
@ -105,7 +105,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
};
|
||||
const {value, error} = OptionsSchema.validate(admonitionsFalse);
|
||||
expect(value).toEqual(admonitionsFalse);
|
||||
expect(error).toBe(undefined);
|
||||
expect(error).toBeUndefined();
|
||||
});
|
||||
|
||||
it('accepts numberPrefixParser function', () => {
|
||||
|
@ -256,7 +256,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
sidebarCollapsible: true,
|
||||
sidebarCollapsed: undefined,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
testValidateOptions({
|
||||
|
@ -264,7 +264,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
sidebarCollapsible: false,
|
||||
sidebarCollapsed: undefined,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
testValidateOptions({
|
||||
|
@ -272,6 +272,6 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
sidebarCollapsible: false,
|
||||
sidebarCollapsed: true,
|
||||
}).sidebarCollapsed,
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,14 +15,14 @@ describe('getSlug', () => {
|
|||
source: '@site/docs/dir/doc.md',
|
||||
sourceDirName: '/dir',
|
||||
}),
|
||||
).toEqual('/dir/doc');
|
||||
).toBe('/dir/doc');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/doc.md',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/doc');
|
||||
).toBe('/dir/subdir/doc');
|
||||
});
|
||||
|
||||
it('handles conventional doc indexes', () => {
|
||||
|
@ -32,42 +32,42 @@ describe('getSlug', () => {
|
|||
source: '@site/docs/dir/subdir/index.md',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/inDEx.mdx',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/readme.md',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/reADMe.mdx',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/subdir.md',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
source: '@site/docs/dir/subdir/suBDir.mdx',
|
||||
sourceDirName: '/dir/subdir',
|
||||
}),
|
||||
).toEqual('/dir/subdir/');
|
||||
).toBe('/dir/subdir/');
|
||||
});
|
||||
|
||||
it('ignores conventional doc index when explicit slug front matter is provided', () => {
|
||||
|
@ -78,7 +78,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir/subdir',
|
||||
frontMatterSlug: '/my/frontMatterSlug',
|
||||
}),
|
||||
).toEqual('/my/frontMatterSlug');
|
||||
).toBe('/my/frontMatterSlug');
|
||||
});
|
||||
|
||||
it('can strip dir number prefixes', () => {
|
||||
|
@ -89,7 +89,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/001-dir1/002-dir2',
|
||||
stripDirNumberPrefixes: true,
|
||||
}),
|
||||
).toEqual('/dir1/dir2/doc');
|
||||
).toBe('/dir1/dir2/doc');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
|
@ -97,7 +97,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/001-dir1/002-dir2',
|
||||
stripDirNumberPrefixes: false,
|
||||
}),
|
||||
).toEqual('/001-dir1/002-dir2/doc');
|
||||
).toBe('/001-dir1/002-dir2/doc');
|
||||
});
|
||||
|
||||
// See https://github.com/facebook/docusaurus/issues/3223
|
||||
|
@ -108,16 +108,16 @@ describe('getSlug', () => {
|
|||
source: '@site/docs/dir with spâce/hey $hello/doc.md',
|
||||
sourceDirName: '/dir with spâce/hey $hello',
|
||||
}),
|
||||
).toEqual('/dir with spâce/hey $hello/my dôc');
|
||||
).toBe('/dir with spâce/hey $hello/my dôc');
|
||||
});
|
||||
|
||||
it('handles current dir', () => {
|
||||
expect(
|
||||
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '.'}),
|
||||
).toEqual('/doc');
|
||||
).toBe('/doc');
|
||||
expect(
|
||||
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '/'}),
|
||||
).toEqual('/doc');
|
||||
).toBe('/doc');
|
||||
});
|
||||
|
||||
it('resolves absolute slug front matter', () => {
|
||||
|
@ -128,7 +128,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '.',
|
||||
frontMatterSlug: '/abc/def',
|
||||
}),
|
||||
).toEqual('/abc/def');
|
||||
).toBe('/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -136,7 +136,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: './any',
|
||||
frontMatterSlug: '/abc/def',
|
||||
}),
|
||||
).toEqual('/abc/def');
|
||||
).toBe('/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -144,7 +144,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: './any/any',
|
||||
frontMatterSlug: '/abc/def',
|
||||
}),
|
||||
).toEqual('/abc/def');
|
||||
).toBe('/abc/def');
|
||||
});
|
||||
|
||||
it('resolves relative slug front matter', () => {
|
||||
|
@ -155,7 +155,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '.',
|
||||
frontMatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/abc/def');
|
||||
).toBe('/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -163,7 +163,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir',
|
||||
frontMatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/dir/abc/def');
|
||||
).toBe('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -171,7 +171,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: 'unslashedDir',
|
||||
frontMatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/unslashedDir/abc/def');
|
||||
).toBe('/unslashedDir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -179,7 +179,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: 'dir/subdir',
|
||||
frontMatterSlug: 'abc/def',
|
||||
}),
|
||||
).toEqual('/dir/subdir/abc/def');
|
||||
).toBe('/dir/subdir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -187,7 +187,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir',
|
||||
frontMatterSlug: './abc/def',
|
||||
}),
|
||||
).toEqual('/dir/abc/def');
|
||||
).toBe('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -195,7 +195,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir',
|
||||
frontMatterSlug: './abc/../def',
|
||||
}),
|
||||
).toEqual('/dir/def');
|
||||
).toBe('/dir/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -203,7 +203,7 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir/subdir',
|
||||
frontMatterSlug: '../abc/def',
|
||||
}),
|
||||
).toEqual('/dir/abc/def');
|
||||
).toBe('/dir/abc/def');
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -211,6 +211,6 @@ describe('getSlug', () => {
|
|||
sourceDirName: '/dir/subdir',
|
||||
frontMatterSlug: '../../../../../abc/../def',
|
||||
}),
|
||||
).toEqual('/def');
|
||||
).toBe('/def');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,8 +32,8 @@ describe('docsClientUtils', () => {
|
|||
},
|
||||
};
|
||||
|
||||
expect(getActivePlugin(data, '/')).toEqual(undefined);
|
||||
expect(getActivePlugin(data, '/xyz')).toEqual(undefined);
|
||||
expect(getActivePlugin(data, '/')).toBeUndefined();
|
||||
expect(getActivePlugin(data, '/xyz')).toBeUndefined();
|
||||
|
||||
expect(() =>
|
||||
getActivePlugin(data, '/', {failfast: true}),
|
||||
|
@ -73,7 +73,7 @@ describe('docsClientUtils', () => {
|
|||
versions: [],
|
||||
},
|
||||
};
|
||||
expect(getActivePlugin(onePluginAtRoot, '/android/foo').pluginId).toEqual(
|
||||
expect(getActivePlugin(onePluginAtRoot, '/android/foo').pluginId).toBe(
|
||||
'pluginAndroidId',
|
||||
);
|
||||
const onePluginAtRootReversed = {
|
||||
|
@ -88,7 +88,7 @@ describe('docsClientUtils', () => {
|
|||
};
|
||||
expect(
|
||||
getActivePlugin(onePluginAtRootReversed, '/android/foo').pluginId,
|
||||
).toEqual('pluginAndroidId');
|
||||
).toBe('pluginAndroidId');
|
||||
});
|
||||
|
||||
it('getLatestVersion', () => {
|
||||
|
@ -158,19 +158,19 @@ describe('docsClientUtils', () => {
|
|||
],
|
||||
};
|
||||
|
||||
expect(getActiveVersion(data, '/someUnknownPath')).toEqual(undefined);
|
||||
expect(getActiveVersion(data, '/someUnknownPath')).toBeUndefined();
|
||||
|
||||
expect(getActiveVersion(data, '/docs/next')?.name).toEqual('next');
|
||||
expect(getActiveVersion(data, '/docs/next/')?.name).toEqual('next');
|
||||
expect(getActiveVersion(data, '/docs/next/someDoc')?.name).toEqual('next');
|
||||
expect(getActiveVersion(data, '/docs/next')?.name).toBe('next');
|
||||
expect(getActiveVersion(data, '/docs/next/')?.name).toBe('next');
|
||||
expect(getActiveVersion(data, '/docs/next/someDoc')?.name).toBe('next');
|
||||
|
||||
expect(getActiveVersion(data, '/docs')?.name).toEqual('version2');
|
||||
expect(getActiveVersion(data, '/docs/')?.name).toEqual('version2');
|
||||
expect(getActiveVersion(data, '/docs/someDoc')?.name).toEqual('version2');
|
||||
expect(getActiveVersion(data, '/docs')?.name).toBe('version2');
|
||||
expect(getActiveVersion(data, '/docs/')?.name).toBe('version2');
|
||||
expect(getActiveVersion(data, '/docs/someDoc')?.name).toBe('version2');
|
||||
|
||||
expect(getActiveVersion(data, '/docs/version1')?.name).toEqual('version1');
|
||||
expect(getActiveVersion(data, '/docs/version1')?.name).toEqual('version1');
|
||||
expect(getActiveVersion(data, '/docs/version1/someDoc')?.name).toEqual(
|
||||
expect(getActiveVersion(data, '/docs/version1')?.name).toBe('version1');
|
||||
expect(getActiveVersion(data, '/docs/version1')?.name).toBe('version1');
|
||||
expect(getActiveVersion(data, '/docs/version1/someDoc')?.name).toBe(
|
||||
'version1',
|
||||
);
|
||||
});
|
||||
|
|
|
@ -132,18 +132,18 @@ describe('createSidebarsUtils', () => {
|
|||
} = createSidebarsUtils(sidebars);
|
||||
|
||||
it('getFirstDocIdOfFirstSidebar', async () => {
|
||||
expect(getFirstDocIdOfFirstSidebar()).toEqual('doc1');
|
||||
expect(getFirstDocIdOfFirstSidebar()).toBe('doc1');
|
||||
});
|
||||
|
||||
it('getSidebarNameByDocId', async () => {
|
||||
expect(getSidebarNameByDocId('doc1')).toEqual('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc2')).toEqual('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc3')).toEqual('sidebar2');
|
||||
expect(getSidebarNameByDocId('doc4')).toEqual('sidebar2');
|
||||
expect(getSidebarNameByDocId('doc5')).toEqual('sidebar3');
|
||||
expect(getSidebarNameByDocId('doc6')).toEqual('sidebar3');
|
||||
expect(getSidebarNameByDocId('doc7')).toEqual('sidebar3');
|
||||
expect(getSidebarNameByDocId('unknown_id')).toEqual(undefined);
|
||||
expect(getSidebarNameByDocId('doc1')).toBe('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc2')).toBe('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc3')).toBe('sidebar2');
|
||||
expect(getSidebarNameByDocId('doc4')).toBe('sidebar2');
|
||||
expect(getSidebarNameByDocId('doc5')).toBe('sidebar3');
|
||||
expect(getSidebarNameByDocId('doc6')).toBe('sidebar3');
|
||||
expect(getSidebarNameByDocId('doc7')).toBe('sidebar3');
|
||||
expect(getSidebarNameByDocId('unknown_id')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('getDocNavigation', async () => {
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
"devDependencies": {
|
||||
"@docusaurus/core": "2.0.0-beta.17",
|
||||
"@docusaurus/types": "2.0.0-beta.17",
|
||||
"@testing-library/react-hooks": "^7.0.2",
|
||||
"fs-extra": "^10.0.1",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`useTreeifiedTOC treeifies TOC without filtering 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
"children": Array [],
|
||||
"id": "foxtrot",
|
||||
"level": 6,
|
||||
"value": "Foxtrot",
|
||||
},
|
||||
],
|
||||
"id": "echo",
|
||||
"level": 5,
|
||||
"value": "Echo",
|
||||
},
|
||||
],
|
||||
"id": "delta",
|
||||
"level": 4,
|
||||
"value": "Delta",
|
||||
},
|
||||
],
|
||||
"id": "charlie",
|
||||
"level": 3,
|
||||
"value": "Charlie",
|
||||
},
|
||||
],
|
||||
"id": "bravo",
|
||||
"level": 2,
|
||||
"value": "Bravo",
|
||||
},
|
||||
]
|
||||
`;
|
|
@ -13,45 +13,45 @@ import {
|
|||
|
||||
describe('parseCodeBlockTitle', () => {
|
||||
it('parses double quote delimited title', () => {
|
||||
expect(parseCodeBlockTitle(`title="index.js"`)).toEqual(`index.js`);
|
||||
expect(parseCodeBlockTitle(`title="index.js"`)).toBe(`index.js`);
|
||||
});
|
||||
|
||||
it('parses single quote delimited title', () => {
|
||||
expect(parseCodeBlockTitle(`title='index.js'`)).toEqual(`index.js`);
|
||||
expect(parseCodeBlockTitle(`title='index.js'`)).toBe(`index.js`);
|
||||
});
|
||||
|
||||
it('does not parse mismatched quote delimiters', () => {
|
||||
expect(parseCodeBlockTitle(`title="index.js'`)).toEqual(``);
|
||||
expect(parseCodeBlockTitle(`title="index.js'`)).toBe(``);
|
||||
});
|
||||
|
||||
it('parses undefined metastring', () => {
|
||||
expect(parseCodeBlockTitle(undefined)).toEqual(``);
|
||||
expect(parseCodeBlockTitle(undefined)).toBe(``);
|
||||
});
|
||||
|
||||
it('parses metastring with no title specified', () => {
|
||||
expect(parseCodeBlockTitle(`{1,2-3}`)).toEqual(``);
|
||||
expect(parseCodeBlockTitle(`{1,2-3}`)).toBe(``);
|
||||
});
|
||||
|
||||
it('parses with multiple metadata title first', () => {
|
||||
expect(parseCodeBlockTitle(`title="index.js" label="JavaScript"`)).toEqual(
|
||||
expect(parseCodeBlockTitle(`title="index.js" label="JavaScript"`)).toBe(
|
||||
`index.js`,
|
||||
);
|
||||
});
|
||||
|
||||
it('parses with multiple metadata title last', () => {
|
||||
expect(parseCodeBlockTitle(`label="JavaScript" title="index.js"`)).toEqual(
|
||||
expect(parseCodeBlockTitle(`label="JavaScript" title="index.js"`)).toBe(
|
||||
`index.js`,
|
||||
);
|
||||
});
|
||||
|
||||
it('parses double quotes when delimited by single quotes', () => {
|
||||
expect(parseCodeBlockTitle(`title='console.log("Hello, World!")'`)).toEqual(
|
||||
expect(parseCodeBlockTitle(`title='console.log("Hello, World!")'`)).toBe(
|
||||
`console.log("Hello, World!")`,
|
||||
);
|
||||
});
|
||||
|
||||
it('parses single quotes when delimited by double quotes', () => {
|
||||
expect(parseCodeBlockTitle(`title="console.log('Hello, World!')"`)).toEqual(
|
||||
expect(parseCodeBlockTitle(`title="console.log('Hello, World!')"`)).toBe(
|
||||
`console.log('Hello, World!')`,
|
||||
);
|
||||
});
|
||||
|
@ -59,8 +59,8 @@ describe('parseCodeBlockTitle', () => {
|
|||
|
||||
describe('parseLanguage', () => {
|
||||
it('works', () => {
|
||||
expect(parseLanguage('language-foo xxx yyy')).toEqual('foo');
|
||||
expect(parseLanguage('xxxxx language-foo yyy')).toEqual('foo');
|
||||
expect(parseLanguage('language-foo xxx yyy')).toBe('foo');
|
||||
expect(parseLanguage('xxxxx language-foo yyy')).toBe('foo');
|
||||
expect(parseLanguage('xx-language-foo yyyy')).toBeUndefined();
|
||||
expect(parseLanguage('xxx yyy zzz')).toBeUndefined();
|
||||
});
|
||||
|
|
|
@ -16,8 +16,11 @@ import {
|
|||
useDocsSidebar,
|
||||
DocsSidebarProvider,
|
||||
findSidebarCategory,
|
||||
getBreadcrumbs,
|
||||
useCurrentSidebarCategory,
|
||||
useSidebarBreadcrumbs,
|
||||
} from '../docsUtils';
|
||||
import {StaticRouter} from 'react-router-dom';
|
||||
import {Context} from '@docusaurus/docusaurusContext';
|
||||
import type {
|
||||
PropSidebar,
|
||||
PropSidebarItem,
|
||||
|
@ -123,7 +126,7 @@ describe('useDocById', () => {
|
|||
},
|
||||
});
|
||||
|
||||
function callHook(docId: string | undefined) {
|
||||
function mockUseDocById(docId: string | undefined) {
|
||||
const {result} = renderHook(() => useDocById(docId), {
|
||||
wrapper: ({children}) => (
|
||||
<DocsVersionProvider version={version}>{children}</DocsVersionProvider>
|
||||
|
@ -133,25 +136,25 @@ describe('useDocById', () => {
|
|||
}
|
||||
|
||||
it('accepts undefined', () => {
|
||||
expect(callHook(undefined)).toBeUndefined();
|
||||
expect(mockUseDocById(undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('finds doc1', () => {
|
||||
expect(callHook('doc1')).toMatchObject({id: 'doc1'});
|
||||
expect(mockUseDocById('doc1')).toMatchObject({id: 'doc1'});
|
||||
});
|
||||
it('finds doc2', () => {
|
||||
expect(callHook('doc2')).toMatchObject({id: 'doc2'});
|
||||
expect(mockUseDocById('doc2')).toMatchObject({id: 'doc2'});
|
||||
});
|
||||
|
||||
it('throws for doc3', () => {
|
||||
expect(() => callHook('doc3')).toThrowErrorMatchingInlineSnapshot(
|
||||
expect(() => mockUseDocById('doc3')).toThrowErrorMatchingInlineSnapshot(
|
||||
`"no version doc found by id=doc3"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findSidebarCategory', () => {
|
||||
it('os able to return undefined', () => {
|
||||
it('is able to return undefined', () => {
|
||||
expect(findSidebarCategory([], () => false)).toBeUndefined();
|
||||
expect(
|
||||
findSidebarCategory([testCategory(), testCategory()], () => false),
|
||||
|
@ -207,7 +210,7 @@ describe('findFirstCategoryLink', () => {
|
|||
href: undefined,
|
||||
}),
|
||||
),
|
||||
).toEqual(undefined);
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('works with category with link', () => {
|
||||
|
@ -217,7 +220,7 @@ describe('findFirstCategoryLink', () => {
|
|||
href: '/itemPath',
|
||||
}),
|
||||
),
|
||||
).toEqual('/itemPath');
|
||||
).toBe('/itemPath');
|
||||
});
|
||||
|
||||
it('works with category with deeply nested category link', () => {
|
||||
|
@ -239,7 +242,7 @@ describe('findFirstCategoryLink', () => {
|
|||
],
|
||||
}),
|
||||
),
|
||||
).toEqual('/itemPath');
|
||||
).toBe('/itemPath');
|
||||
});
|
||||
|
||||
it('works with category with deeply nested link', () => {
|
||||
|
@ -255,7 +258,7 @@ describe('findFirstCategoryLink', () => {
|
|||
],
|
||||
}),
|
||||
),
|
||||
).toEqual('/itemPath');
|
||||
).toBe('/itemPath');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -267,15 +270,15 @@ describe('isActiveSidebarItem', () => {
|
|||
label: 'Label',
|
||||
};
|
||||
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toBe(false);
|
||||
|
||||
expect(isActiveSidebarItem(item, '/itemPath')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/itemPath')).toBe(true);
|
||||
|
||||
// Ensure it's not trailing slash sensitive:
|
||||
expect(isActiveSidebarItem(item, '/itemPath/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/itemPath/')).toBe(true);
|
||||
expect(
|
||||
isActiveSidebarItem({...item, href: '/itemPath/'}, '/itemPath'),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('works with category href', () => {
|
||||
|
@ -283,15 +286,15 @@ describe('isActiveSidebarItem', () => {
|
|||
href: '/itemPath',
|
||||
});
|
||||
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toBe(false);
|
||||
|
||||
expect(isActiveSidebarItem(item, '/itemPath')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/itemPath')).toBe(true);
|
||||
|
||||
// Ensure it's not trailing slash sensitive:
|
||||
expect(isActiveSidebarItem(item, '/itemPath/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/itemPath/')).toBe(true);
|
||||
expect(
|
||||
isActiveSidebarItem({...item, href: '/itemPath/'}, '/itemPath'),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('works with category nested items', () => {
|
||||
|
@ -316,63 +319,70 @@ describe('isActiveSidebarItem', () => {
|
|||
],
|
||||
});
|
||||
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
||||
expect(isActiveSidebarItem(item, '/unexistingPath')).toBe(false);
|
||||
|
||||
expect(isActiveSidebarItem(item, '/category-path')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-link-path')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-category-path')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-sub-link-path')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/category-path')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-link-path')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-category-path')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-sub-link-path')).toBe(true);
|
||||
|
||||
// Ensure it's not trailing slash sensitive:
|
||||
expect(isActiveSidebarItem(item, '/category-path/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-link-path/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-category-path/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-sub-link-path/')).toEqual(true);
|
||||
expect(isActiveSidebarItem(item, '/category-path/')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-link-path/')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-category-path/')).toBe(true);
|
||||
expect(isActiveSidebarItem(item, '/sub-sub-link-path/')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBreadcrumbs', () => {
|
||||
describe('useSidebarBreadcrumbs', () => {
|
||||
const createUseSidebarBreadcrumbsMock =
|
||||
(sidebar: PropSidebar, breadcrumbsOption?: boolean) => (location: string) =>
|
||||
renderHook(() => useSidebarBreadcrumbs(), {
|
||||
wrapper: ({children}) => (
|
||||
<StaticRouter location={location}>
|
||||
<Context.Provider
|
||||
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
||||
value={{
|
||||
globalData: {
|
||||
'docusaurus-plugin-content-docs': {
|
||||
default: {path: '/', breadcrumbs: breadcrumbsOption},
|
||||
},
|
||||
},
|
||||
}}>
|
||||
<DocsSidebarProvider sidebar={sidebar}>
|
||||
{children}
|
||||
</DocsSidebarProvider>
|
||||
</Context.Provider>
|
||||
</StaticRouter>
|
||||
),
|
||||
}).result.current;
|
||||
it('returns empty for empty sidebar', () => {
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar: [],
|
||||
pathname: '/doesNotExist',
|
||||
}),
|
||||
).toEqual([]);
|
||||
expect(createUseSidebarBreadcrumbsMock([])('/doesNotExist')).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns empty for sidebar but unknown pathname', () => {
|
||||
const sidebar = [testCategory(), testLink()];
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname: '/doesNotExist',
|
||||
}),
|
||||
).toEqual([]);
|
||||
expect(createUseSidebarBreadcrumbsMock(sidebar)('/doesNotExist')).toEqual(
|
||||
[],
|
||||
);
|
||||
});
|
||||
|
||||
it('returns first level category', () => {
|
||||
const pathname = '/somePathName';
|
||||
const sidebar = [testCategory({href: pathname}), testLink()];
|
||||
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname,
|
||||
}),
|
||||
).toEqual([sidebar[0]]);
|
||||
expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([
|
||||
sidebar[0],
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns first level link', () => {
|
||||
const pathname = '/somePathName';
|
||||
const sidebar = [testCategory(), testLink({href: pathname})];
|
||||
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname,
|
||||
}),
|
||||
).toEqual([sidebar[1]]);
|
||||
expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([
|
||||
sidebar[1],
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns nested category', () => {
|
||||
|
@ -403,12 +413,11 @@ describe('getBreadcrumbs', () => {
|
|||
testCategory(),
|
||||
];
|
||||
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname,
|
||||
}),
|
||||
).toEqual([categoryLevel1, categoryLevel2, categoryLevel3]);
|
||||
expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([
|
||||
categoryLevel1,
|
||||
categoryLevel2,
|
||||
categoryLevel3,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns nested link', () => {
|
||||
|
@ -441,11 +450,75 @@ describe('getBreadcrumbs', () => {
|
|||
testCategory(),
|
||||
];
|
||||
|
||||
expect(
|
||||
getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname,
|
||||
}),
|
||||
).toEqual([categoryLevel1, categoryLevel2, categoryLevel3, link]);
|
||||
expect(createUseSidebarBreadcrumbsMock(sidebar)(pathname)).toEqual([
|
||||
categoryLevel1,
|
||||
categoryLevel2,
|
||||
categoryLevel3,
|
||||
link,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns null when breadcrumbs disabled', () => {
|
||||
expect(createUseSidebarBreadcrumbsMock([], false)('/foo')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when there is no sidebar', () => {
|
||||
expect(createUseSidebarBreadcrumbsMock(null, false)('/foo')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useCurrentSidebarCategory', () => {
|
||||
const createUseCurrentSidebarCategoryMock =
|
||||
(sidebar?: PropSidebar) => (location: string) =>
|
||||
renderHook(() => useCurrentSidebarCategory(), {
|
||||
wrapper: ({children}) => (
|
||||
<DocsSidebarProvider sidebar={sidebar}>
|
||||
<StaticRouter location={location}>{children}</StaticRouter>
|
||||
</DocsSidebarProvider>
|
||||
),
|
||||
}).result.current;
|
||||
it('works', () => {
|
||||
const category = {
|
||||
type: 'category',
|
||||
href: '/cat',
|
||||
items: [
|
||||
{type: 'link', href: '/cat/foo', label: 'Foo'},
|
||||
{type: 'link', href: '/cat/bar', label: 'Bar'},
|
||||
{type: 'link', href: '/baz', label: 'Baz'},
|
||||
],
|
||||
};
|
||||
const mockUseCurrentSidebarCategory = createUseCurrentSidebarCategoryMock([
|
||||
{type: 'link', href: '/cat/fake', label: 'Fake'},
|
||||
category,
|
||||
]);
|
||||
expect(mockUseCurrentSidebarCategory('/cat')).toEqual(category);
|
||||
});
|
||||
|
||||
it('throws for non-category index page', () => {
|
||||
const category = {
|
||||
type: 'category',
|
||||
items: [
|
||||
{type: 'link', href: '/cat/foo', label: 'Foo'},
|
||||
{type: 'link', href: '/cat/bar', label: 'Bar'},
|
||||
{type: 'link', href: '/baz', label: 'Baz'},
|
||||
],
|
||||
};
|
||||
const mockUseCurrentSidebarCategory = createUseCurrentSidebarCategoryMock([
|
||||
category,
|
||||
]);
|
||||
expect(() => mockUseCurrentSidebarCategory('/cat'))
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unexpected: sidebar category could not be found for pathname='/cat'.
|
||||
Hook useCurrentSidebarCategory() should only be used on Category pages"
|
||||
`);
|
||||
});
|
||||
|
||||
it('throws when sidebar is missing', () => {
|
||||
const mockUseCurrentSidebarCategory = createUseCurrentSidebarCategoryMock();
|
||||
expect(() =>
|
||||
mockUseCurrentSidebarCategory('/cat'),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unexpected: cant find current sidebar in context"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* 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 {isMultiColumnFooterLinks} from '../footerUtils';
|
||||
|
||||
describe('isMultiColumnFooterLinks', () => {
|
||||
it('works', () => {
|
||||
expect(
|
||||
isMultiColumnFooterLinks([
|
||||
{
|
||||
title: 'section',
|
||||
items: [
|
||||
{href: '/foo', label: 'Foo'},
|
||||
{href: '/bar', label: 'Bar'},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'section2',
|
||||
items: [
|
||||
{href: '/foo', label: 'Foo2'},
|
||||
{href: '/bar', label: 'Bar2'},
|
||||
],
|
||||
},
|
||||
]),
|
||||
).toBe(true);
|
||||
expect(
|
||||
isMultiColumnFooterLinks([
|
||||
{href: '/foo', label: 'Foo'},
|
||||
{href: '/bar', label: 'Bar'},
|
||||
]),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* 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 React from 'react';
|
||||
import {useTitleFormatter} from '../generalUtils';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import {Context} from '@docusaurus/docusaurusContext';
|
||||
import type {DocusaurusContext} from '@docusaurus/types';
|
||||
|
||||
describe('useTitleFormatter', () => {
|
||||
const createUseTitleFormatterMock =
|
||||
(context: DocusaurusContext) => (title?: string) =>
|
||||
renderHook(() => useTitleFormatter(title), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>{children}</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('works', () => {
|
||||
const mockUseTitleFormatter = createUseTitleFormatterMock({
|
||||
siteConfig: {
|
||||
title: 'my site',
|
||||
titleDelimiter: '·',
|
||||
},
|
||||
});
|
||||
expect(mockUseTitleFormatter('a page')).toBe('a page · my site');
|
||||
expect(mockUseTitleFormatter(undefined)).toBe('my site');
|
||||
expect(mockUseTitleFormatter(' ')).toBe('my site');
|
||||
});
|
||||
});
|
|
@ -9,13 +9,13 @@ import {isRegexpStringMatch} from '../regexpUtils';
|
|||
|
||||
describe('isRegexpStringMatch', () => {
|
||||
it('works', () => {
|
||||
expect(isRegexpStringMatch(undefined, 'foo')).toEqual(false);
|
||||
expect(isRegexpStringMatch('bar', undefined)).toEqual(false);
|
||||
expect(isRegexpStringMatch('foo', 'bar')).toEqual(false);
|
||||
expect(isRegexpStringMatch('foo', 'foo')).toEqual(true);
|
||||
expect(isRegexpStringMatch('fooooooooooo', 'foo')).toEqual(false);
|
||||
expect(isRegexpStringMatch('foo', 'fooooooo')).toEqual(true);
|
||||
expect(isRegexpStringMatch('f.*o', 'fggo')).toEqual(true);
|
||||
expect(isRegexpStringMatch('FOO', 'foo')).toEqual(true);
|
||||
expect(isRegexpStringMatch(undefined, 'foo')).toBe(false);
|
||||
expect(isRegexpStringMatch('bar', undefined)).toBe(false);
|
||||
expect(isRegexpStringMatch('foo', 'bar')).toBe(false);
|
||||
expect(isRegexpStringMatch('foo', 'foo')).toBe(true);
|
||||
expect(isRegexpStringMatch('fooooooooooo', 'foo')).toBe(false);
|
||||
expect(isRegexpStringMatch('foo', 'fooooooo')).toBe(true);
|
||||
expect(isRegexpStringMatch('f.*o', 'fggo')).toBe(true);
|
||||
expect(isRegexpStringMatch('FOO', 'foo')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {type Route} from '@generated/routes';
|
||||
import type {Route} from '@docusaurus/types';
|
||||
import {findHomePageRoute} from '../routesUtils';
|
||||
|
||||
describe('findHomePageRoute', () => {
|
||||
|
@ -15,7 +15,7 @@ describe('findHomePageRoute', () => {
|
|||
};
|
||||
|
||||
it('returns undefined for no routes', () => {
|
||||
expect(findHomePageRoute({baseUrl: '/', routes: []})).toEqual(undefined);
|
||||
expect(findHomePageRoute({baseUrl: '/', routes: []})).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns undefined for no homepage', () => {
|
||||
|
@ -37,7 +37,7 @@ describe('findHomePageRoute', () => {
|
|||
},
|
||||
],
|
||||
}),
|
||||
).toEqual(undefined);
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('finds top-level homepage', () => {
|
||||
|
|
|
@ -9,6 +9,6 @@ import {docVersionSearchTag} from '../searchUtils';
|
|||
|
||||
describe('docVersionSearchTag', () => {
|
||||
it('works', () => {
|
||||
expect(docVersionSearchTag('foo', 'bar')).toEqual('docs-foo-bar');
|
||||
expect(docVersionSearchTag('foo', 'bar')).toBe('docs-foo-bar');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,47 +7,50 @@
|
|||
|
||||
import type {TOCItem} from '@docusaurus/types';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import {useFilteredAndTreeifiedTOC} from '../tocUtils';
|
||||
import {useFilteredAndTreeifiedTOC, useTreeifiedTOC} from '../tocUtils';
|
||||
|
||||
const mockTOC: TOCItem[] = [
|
||||
{
|
||||
id: 'bravo',
|
||||
level: 2,
|
||||
value: 'Bravo',
|
||||
},
|
||||
{
|
||||
id: 'charlie',
|
||||
level: 3,
|
||||
value: 'Charlie',
|
||||
},
|
||||
{
|
||||
id: 'delta',
|
||||
level: 4,
|
||||
value: 'Delta',
|
||||
},
|
||||
{
|
||||
id: 'echo',
|
||||
level: 5,
|
||||
value: 'Echo',
|
||||
},
|
||||
{
|
||||
id: 'foxtrot',
|
||||
level: 6,
|
||||
value: 'Foxtrot',
|
||||
},
|
||||
];
|
||||
|
||||
describe('useTreeifiedTOC', () => {
|
||||
it('treeifies TOC without filtering', () => {
|
||||
expect(
|
||||
renderHook(() => useTreeifiedTOC(mockTOC)).result.current,
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useFilteredAndTreeifiedTOC', () => {
|
||||
it('filters a toc with all heading levels', () => {
|
||||
const toc: TOCItem[] = [
|
||||
{
|
||||
id: 'alpha',
|
||||
level: 1,
|
||||
value: 'alpha',
|
||||
},
|
||||
{
|
||||
id: 'bravo',
|
||||
level: 2,
|
||||
value: 'Bravo',
|
||||
},
|
||||
{
|
||||
id: 'charlie',
|
||||
level: 3,
|
||||
value: 'Charlie',
|
||||
},
|
||||
{
|
||||
id: 'delta',
|
||||
level: 4,
|
||||
value: 'Delta',
|
||||
},
|
||||
{
|
||||
id: 'echo',
|
||||
level: 5,
|
||||
value: 'Echo',
|
||||
},
|
||||
{
|
||||
id: 'foxtrot',
|
||||
level: 6,
|
||||
value: 'Foxtrot',
|
||||
},
|
||||
];
|
||||
|
||||
expect(
|
||||
renderHook(() =>
|
||||
useFilteredAndTreeifiedTOC({
|
||||
toc,
|
||||
toc: mockTOC,
|
||||
minHeadingLevel: 2,
|
||||
maxHeadingLevel: 2,
|
||||
}),
|
||||
|
@ -64,7 +67,7 @@ describe('useFilteredAndTreeifiedTOC', () => {
|
|||
expect(
|
||||
renderHook(() =>
|
||||
useFilteredAndTreeifiedTOC({
|
||||
toc,
|
||||
toc: mockTOC,
|
||||
minHeadingLevel: 3,
|
||||
maxHeadingLevel: 3,
|
||||
}),
|
||||
|
@ -81,7 +84,7 @@ describe('useFilteredAndTreeifiedTOC', () => {
|
|||
expect(
|
||||
renderHook(() =>
|
||||
useFilteredAndTreeifiedTOC({
|
||||
toc,
|
||||
toc: mockTOC,
|
||||
minHeadingLevel: 2,
|
||||
maxHeadingLevel: 3,
|
||||
}),
|
||||
|
@ -105,7 +108,7 @@ describe('useFilteredAndTreeifiedTOC', () => {
|
|||
expect(
|
||||
renderHook(() =>
|
||||
useFilteredAndTreeifiedTOC({
|
||||
toc,
|
||||
toc: mockTOC,
|
||||
minHeadingLevel: 2,
|
||||
maxHeadingLevel: 4,
|
||||
}),
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
* 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 React from 'react';
|
||||
import {useAlternatePageUtils} from '../useAlternatePageUtils';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import {StaticRouter} from 'react-router-dom';
|
||||
import {Context} from '@docusaurus/docusaurusContext';
|
||||
import type {DocusaurusContext} from '@docusaurus/types';
|
||||
|
||||
describe('useAlternatePageUtils', () => {
|
||||
const createUseAlternatePageUtilsMock =
|
||||
(context: DocusaurusContext) => (location: string) =>
|
||||
renderHook(() => useAlternatePageUtils(), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>
|
||||
<StaticRouter location={location}>{children}</StaticRouter>
|
||||
</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('works for baseUrl: / and currentLocale = defaultLocale', () => {
|
||||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'en'},
|
||||
});
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/zh-Hans/');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/foo').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/zh-Hans/foo');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/foo').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: true,
|
||||
}),
|
||||
).toBe('https://example.com/zh-Hans/foo');
|
||||
});
|
||||
|
||||
it('works for baseUrl: / and currentLocale /= defaultLocale', () => {
|
||||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/zh-Hans/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'zh-Hans'},
|
||||
});
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/zh-Hans/').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/zh-Hans/foo').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/foo');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/zh-Hans/foo').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: true,
|
||||
}),
|
||||
).toBe('https://example.com/foo');
|
||||
});
|
||||
|
||||
it('works for non-root base URL and currentLocale = defaultLocale', () => {
|
||||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/base/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'en'},
|
||||
});
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/base/zh-Hans/');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/foo').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/base/zh-Hans/foo');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/foo').createUrl({
|
||||
locale: 'zh-Hans',
|
||||
fullyQualified: true,
|
||||
}),
|
||||
).toBe('https://example.com/base/zh-Hans/foo');
|
||||
});
|
||||
|
||||
it('works for non-root base URL and currentLocale /= defaultLocale', () => {
|
||||
const mockUseAlternatePageUtils = createUseAlternatePageUtilsMock({
|
||||
siteConfig: {baseUrl: '/base/zh-Hans/', url: 'https://example.com'},
|
||||
i18n: {defaultLocale: 'en', currentLocale: 'zh-Hans'},
|
||||
});
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/zh-Hans/').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/base/');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/zh-Hans/foo').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: false,
|
||||
}),
|
||||
).toBe('/base/foo');
|
||||
expect(
|
||||
mockUseAlternatePageUtils('/base/zh-Hans/foo').createUrl({
|
||||
locale: 'en',
|
||||
fullyQualified: true,
|
||||
}),
|
||||
).toBe('https://example.com/base/foo');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* 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 React from 'react';
|
||||
import {useLocalPathname} from '../useLocalPathname';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import {StaticRouter} from 'react-router-dom';
|
||||
import {Context} from '@docusaurus/docusaurusContext';
|
||||
import type {DocusaurusContext} from '@docusaurus/types';
|
||||
|
||||
describe('useLocalPathname', () => {
|
||||
const createUseLocalPathnameMock =
|
||||
(context: DocusaurusContext) => (location: string) =>
|
||||
renderHook(() => useLocalPathname(), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>
|
||||
<StaticRouter location={location}>{children}</StaticRouter>
|
||||
</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('works for baseUrl: /', () => {
|
||||
const mockUseLocalPathname = createUseLocalPathnameMock({
|
||||
siteConfig: {baseUrl: '/'},
|
||||
});
|
||||
expect(mockUseLocalPathname('/foo')).toBe('/foo');
|
||||
});
|
||||
|
||||
it('works for non-root baseUrl', () => {
|
||||
const mockUseLocalPathname = createUseLocalPathnameMock({
|
||||
siteConfig: {baseUrl: '/base/'},
|
||||
});
|
||||
expect(mockUseLocalPathname('/base/foo')).toBe('/foo');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* 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 {jest} from '@jest/globals';
|
||||
import React from 'react';
|
||||
import {usePluralForm} from '../usePluralForm';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import {Context} from '@docusaurus/docusaurusContext';
|
||||
import type {DocusaurusContext} from '@docusaurus/types';
|
||||
|
||||
describe('usePluralForm', () => {
|
||||
const createUsePluralFormMock = (context: DocusaurusContext) => () =>
|
||||
renderHook(() => usePluralForm(), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>{children}</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('returns the right plural', () => {
|
||||
const mockUsePluralForm = createUsePluralFormMock({
|
||||
i18n: {
|
||||
currentLocale: 'en',
|
||||
},
|
||||
});
|
||||
expect(mockUsePluralForm().selectMessage(1, 'one|many')).toBe('one');
|
||||
expect(mockUsePluralForm().selectMessage(10, 'one|many')).toBe('many');
|
||||
});
|
||||
|
||||
it('warns against too many plurals', () => {
|
||||
const mockUsePluralForm = createUsePluralFormMock({
|
||||
i18n: {
|
||||
currentLocale: 'zh-Hans',
|
||||
},
|
||||
});
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
expect(mockUsePluralForm().selectMessage(1, 'one|many')).toBe('one');
|
||||
expect(mockUsePluralForm().selectMessage(10, 'one|many')).toBe('one');
|
||||
expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot(
|
||||
`"For locale=zh-Hans, a maximum of 1 plural forms are expected (other), but the message contains 2: one|many"`,
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the last with not enough plurals', () => {
|
||||
const mockUsePluralForm = createUsePluralFormMock({
|
||||
i18n: {
|
||||
currentLocale: 'en',
|
||||
},
|
||||
});
|
||||
expect(mockUsePluralForm().selectMessage(10, 'many')).toBe('many');
|
||||
});
|
||||
|
||||
it('falls back when Intl.PluralForms is not available', () => {
|
||||
const mockUsePluralForm = createUsePluralFormMock({
|
||||
i18n: {
|
||||
currentLocale: 'zh-Hans',
|
||||
},
|
||||
});
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
const pluralMock = jest
|
||||
.spyOn(Intl, 'PluralRules')
|
||||
.mockImplementation(() => undefined);
|
||||
expect(mockUsePluralForm().selectMessage(1, 'one|many')).toBe('one');
|
||||
expect(mockUsePluralForm().selectMessage(10, 'one|many')).toBe('many');
|
||||
expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot(`
|
||||
"Failed to use Intl.PluralRules for locale \\"zh-Hans\\".
|
||||
Docusaurus will fallback to the default (English) implementation.
|
||||
Error: pluralRules.resolvedOptions is not a function
|
||||
"
|
||||
`);
|
||||
pluralMock.mockRestore();
|
||||
});
|
||||
});
|
|
@ -187,7 +187,7 @@ export function isActiveSidebarItem(
|
|||
return false;
|
||||
}
|
||||
|
||||
export function getBreadcrumbs({
|
||||
function getBreadcrumbs({
|
||||
sidebar,
|
||||
pathname,
|
||||
}: {
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
|
||||
export const useTitleFormatter = (title?: string | undefined): string => {
|
||||
export function useTitleFormatter(title?: string | undefined): string {
|
||||
const {siteConfig} = useDocusaurusContext();
|
||||
const {title: siteTitle, titleDelimiter} = siteConfig;
|
||||
return title && title.trim().length
|
||||
? `${title.trim()} ${titleDelimiter} ${siteTitle}`
|
||||
: siteTitle;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import GeneratedRoutes, {type Route} from '@generated/routes';
|
||||
import generatedRoutes from '@generated/routes';
|
||||
import {useMemo} from 'react';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import type {Route} from '@docusaurus/types';
|
||||
|
||||
// Note that all sites don't always have a homepage in practice
|
||||
// See https://github.com/facebook/docusaurus/pull/6517#issuecomment-1048709116
|
||||
|
@ -48,7 +49,7 @@ export function useHomePageRoute(): Route | undefined {
|
|||
return useMemo(
|
||||
() =>
|
||||
findHomePageRoute({
|
||||
routes: GeneratedRoutes,
|
||||
routes: generatedRoutes,
|
||||
baseUrl,
|
||||
}),
|
||||
[baseUrl],
|
||||
|
|
|
@ -70,21 +70,13 @@ function useLocalePluralForms(): LocalePluralForms {
|
|||
i18n: {currentLocale},
|
||||
} = useDocusaurusContext();
|
||||
return useMemo(() => {
|
||||
// @ts-expect-error checking Intl.PluralRules in case browser doesn't
|
||||
// have it (e.g Safari 12-)
|
||||
if (Intl.PluralRules) {
|
||||
try {
|
||||
return createLocalePluralForms(currentLocale);
|
||||
} catch {
|
||||
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
||||
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
||||
try {
|
||||
return createLocalePluralForms(currentLocale);
|
||||
} catch (err) {
|
||||
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
||||
Docusaurus will fallback to the default (English) implementation.
|
||||
Error: ${(err as Error).message}
|
||||
`);
|
||||
return EnglishPluralForms;
|
||||
}
|
||||
} else {
|
||||
console.error(`Intl.PluralRules not available!
|
||||
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
||||
`);
|
||||
return EnglishPluralForms;
|
||||
}
|
||||
}, [currentLocale]);
|
||||
|
@ -103,7 +95,7 @@ function selectPluralMessage(
|
|||
}
|
||||
if (parts.length > localePluralForms.pluralForms.length) {
|
||||
console.error(
|
||||
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length} plural forms: ${pluralMessages} `,
|
||||
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}: ${pluralMessages}`,
|
||||
);
|
||||
}
|
||||
const pluralForm = localePluralForms.select(count);
|
||||
|
|
8
packages/docusaurus-types/src/index.d.ts
vendored
8
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -372,6 +372,14 @@ export interface RouteConfig {
|
|||
[propName: string]: unknown;
|
||||
}
|
||||
|
||||
export type Route = {
|
||||
readonly path: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
readonly component: any;
|
||||
readonly exact?: boolean;
|
||||
readonly routes?: Route[];
|
||||
};
|
||||
|
||||
// Aliases used for Webpack resolution (when using docusaurus swizzle)
|
||||
export interface ThemeAliases {
|
||||
[alias: string]: string;
|
||||
|
|
|
@ -18,161 +18,161 @@ function params(
|
|||
|
||||
describe('applyTrailingSlash', () => {
|
||||
it('applies to empty', () => {
|
||||
expect(applyTrailingSlash('', params(true))).toEqual('/');
|
||||
expect(applyTrailingSlash('', params(false))).toEqual('');
|
||||
expect(applyTrailingSlash('', params(undefined))).toEqual('');
|
||||
expect(applyTrailingSlash('', params(true))).toBe('/');
|
||||
expect(applyTrailingSlash('', params(false))).toBe('');
|
||||
expect(applyTrailingSlash('', params(undefined))).toBe('');
|
||||
});
|
||||
|
||||
it('does not apply to /', () => {
|
||||
expect(applyTrailingSlash('/', params(true))).toEqual('/');
|
||||
expect(applyTrailingSlash('/', params(false))).toEqual('/');
|
||||
expect(applyTrailingSlash('/', params(undefined))).toEqual('/');
|
||||
expect(applyTrailingSlash('/', params(true))).toBe('/');
|
||||
expect(applyTrailingSlash('/', params(false))).toBe('/');
|
||||
expect(applyTrailingSlash('/', params(undefined))).toBe('/');
|
||||
|
||||
expect(applyTrailingSlash('/?query#anchor', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/?query#anchor', params(true))).toBe(
|
||||
'/?query#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/?query#anchor', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/?query#anchor', params(false))).toBe(
|
||||
'/?query#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/?query#anchor', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/?query#anchor', params(undefined))).toBe(
|
||||
'/?query#anchor',
|
||||
);
|
||||
});
|
||||
|
||||
it('does not apply to /baseUrl/', () => {
|
||||
const baseUrl = '/baseUrl/';
|
||||
expect(applyTrailingSlash('/baseUrl/', params(true, baseUrl))).toEqual(
|
||||
expect(applyTrailingSlash('/baseUrl/', params(true, baseUrl))).toBe(
|
||||
'/baseUrl/',
|
||||
);
|
||||
expect(applyTrailingSlash('/baseUrl/', params(false, baseUrl))).toEqual(
|
||||
expect(applyTrailingSlash('/baseUrl/', params(false, baseUrl))).toBe(
|
||||
'/baseUrl/',
|
||||
);
|
||||
expect(applyTrailingSlash('/baseUrl/', params(undefined, baseUrl))).toEqual(
|
||||
expect(applyTrailingSlash('/baseUrl/', params(undefined, baseUrl))).toBe(
|
||||
'/baseUrl/',
|
||||
);
|
||||
|
||||
expect(
|
||||
applyTrailingSlash('/baseUrl/?query#anchor', params(true, baseUrl)),
|
||||
).toEqual('/baseUrl/?query#anchor');
|
||||
).toBe('/baseUrl/?query#anchor');
|
||||
expect(
|
||||
applyTrailingSlash('/baseUrl/?query#anchor', params(false, baseUrl)),
|
||||
).toEqual('/baseUrl/?query#anchor');
|
||||
).toBe('/baseUrl/?query#anchor');
|
||||
expect(
|
||||
applyTrailingSlash('/baseUrl/?query#anchor', params(undefined, baseUrl)),
|
||||
).toEqual('/baseUrl/?query#anchor');
|
||||
).toBe('/baseUrl/?query#anchor');
|
||||
});
|
||||
|
||||
it('does not apply to #anchor links', () => {
|
||||
expect(applyTrailingSlash('#', params(true))).toEqual('#');
|
||||
expect(applyTrailingSlash('#', params(false))).toEqual('#');
|
||||
expect(applyTrailingSlash('#', params(undefined))).toEqual('#');
|
||||
expect(applyTrailingSlash('#anchor', params(true))).toEqual('#anchor');
|
||||
expect(applyTrailingSlash('#anchor', params(false))).toEqual('#anchor');
|
||||
expect(applyTrailingSlash('#anchor', params(undefined))).toEqual('#anchor');
|
||||
expect(applyTrailingSlash('#', params(true))).toBe('#');
|
||||
expect(applyTrailingSlash('#', params(false))).toBe('#');
|
||||
expect(applyTrailingSlash('#', params(undefined))).toBe('#');
|
||||
expect(applyTrailingSlash('#anchor', params(true))).toBe('#anchor');
|
||||
expect(applyTrailingSlash('#anchor', params(false))).toBe('#anchor');
|
||||
expect(applyTrailingSlash('#anchor', params(undefined))).toBe('#anchor');
|
||||
});
|
||||
|
||||
it('applies to simple paths', () => {
|
||||
expect(applyTrailingSlash('abc', params(true))).toEqual('abc/');
|
||||
expect(applyTrailingSlash('abc', params(false))).toEqual('abc');
|
||||
expect(applyTrailingSlash('abc', params(undefined))).toEqual('abc');
|
||||
expect(applyTrailingSlash('abc/', params(true))).toEqual('abc/');
|
||||
expect(applyTrailingSlash('abc/', params(false))).toEqual('abc');
|
||||
expect(applyTrailingSlash('abc/', params(undefined))).toEqual('abc/');
|
||||
expect(applyTrailingSlash('/abc', params(true))).toEqual('/abc/');
|
||||
expect(applyTrailingSlash('/abc', params(false))).toEqual('/abc');
|
||||
expect(applyTrailingSlash('/abc', params(undefined))).toEqual('/abc');
|
||||
expect(applyTrailingSlash('/abc/', params(true))).toEqual('/abc/');
|
||||
expect(applyTrailingSlash('/abc/', params(false))).toEqual('/abc');
|
||||
expect(applyTrailingSlash('/abc/', params(undefined))).toEqual('/abc/');
|
||||
expect(applyTrailingSlash('abc', params(true))).toBe('abc/');
|
||||
expect(applyTrailingSlash('abc', params(false))).toBe('abc');
|
||||
expect(applyTrailingSlash('abc', params(undefined))).toBe('abc');
|
||||
expect(applyTrailingSlash('abc/', params(true))).toBe('abc/');
|
||||
expect(applyTrailingSlash('abc/', params(false))).toBe('abc');
|
||||
expect(applyTrailingSlash('abc/', params(undefined))).toBe('abc/');
|
||||
expect(applyTrailingSlash('/abc', params(true))).toBe('/abc/');
|
||||
expect(applyTrailingSlash('/abc', params(false))).toBe('/abc');
|
||||
expect(applyTrailingSlash('/abc', params(undefined))).toBe('/abc');
|
||||
expect(applyTrailingSlash('/abc/', params(true))).toBe('/abc/');
|
||||
expect(applyTrailingSlash('/abc/', params(false))).toBe('/abc');
|
||||
expect(applyTrailingSlash('/abc/', params(undefined))).toBe('/abc/');
|
||||
});
|
||||
|
||||
it('applies to path with #anchor', () => {
|
||||
expect(applyTrailingSlash('/abc#anchor', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc#anchor', params(true))).toBe(
|
||||
'/abc/#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc#anchor', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc#anchor', params(false))).toBe(
|
||||
'/abc#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc#anchor', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/abc#anchor', params(undefined))).toBe(
|
||||
'/abc#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(true))).toBe(
|
||||
'/abc/#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(false))).toBe(
|
||||
'/abc#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/#anchor', params(undefined))).toBe(
|
||||
'/abc/#anchor',
|
||||
);
|
||||
});
|
||||
|
||||
it('applies to path with ?search', () => {
|
||||
expect(applyTrailingSlash('/abc?search', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search', params(true))).toBe(
|
||||
'/abc/?search',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc?search', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search', params(false))).toBe(
|
||||
'/abc?search',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc?search', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search', params(undefined))).toBe(
|
||||
'/abc?search',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/?search', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/?search', params(true))).toBe(
|
||||
'/abc/?search',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/?search', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/?search', params(false))).toBe(
|
||||
'/abc?search',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/?search', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/?search', params(undefined))).toBe(
|
||||
'/abc/?search',
|
||||
);
|
||||
});
|
||||
|
||||
it('applies to path with ?search#anchor', () => {
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(true))).toBe(
|
||||
'/abc/?search#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(false))).toBe(
|
||||
'/abc?search#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(undefined))).toEqual(
|
||||
expect(applyTrailingSlash('/abc?search#anchor', params(undefined))).toBe(
|
||||
'/abc?search#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/?search#anchor', params(true))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/?search#anchor', params(true))).toBe(
|
||||
'/abc/?search#anchor',
|
||||
);
|
||||
expect(applyTrailingSlash('/abc/?search#anchor', params(false))).toEqual(
|
||||
expect(applyTrailingSlash('/abc/?search#anchor', params(false))).toBe(
|
||||
'/abc?search#anchor',
|
||||
);
|
||||
expect(
|
||||
applyTrailingSlash('/abc/?search#anchor', params(undefined)),
|
||||
).toEqual('/abc/?search#anchor');
|
||||
expect(applyTrailingSlash('/abc/?search#anchor', params(undefined))).toBe(
|
||||
'/abc/?search#anchor',
|
||||
);
|
||||
});
|
||||
|
||||
it('applies to fully qualified urls', () => {
|
||||
expect(
|
||||
applyTrailingSlash('https://xyz.com/abc?search#anchor', params(true)),
|
||||
).toEqual('https://xyz.com/abc/?search#anchor');
|
||||
).toBe('https://xyz.com/abc/?search#anchor');
|
||||
expect(
|
||||
applyTrailingSlash('https://xyz.com/abc?search#anchor', params(false)),
|
||||
).toEqual('https://xyz.com/abc?search#anchor');
|
||||
).toBe('https://xyz.com/abc?search#anchor');
|
||||
expect(
|
||||
applyTrailingSlash(
|
||||
'https://xyz.com/abc?search#anchor',
|
||||
params(undefined),
|
||||
),
|
||||
).toEqual('https://xyz.com/abc?search#anchor');
|
||||
).toBe('https://xyz.com/abc?search#anchor');
|
||||
expect(
|
||||
applyTrailingSlash('https://xyz.com/abc/?search#anchor', params(true)),
|
||||
).toEqual('https://xyz.com/abc/?search#anchor');
|
||||
).toBe('https://xyz.com/abc/?search#anchor');
|
||||
expect(
|
||||
applyTrailingSlash('https://xyz.com/abc/?search#anchor', params(false)),
|
||||
).toEqual('https://xyz.com/abc?search#anchor');
|
||||
).toBe('https://xyz.com/abc?search#anchor');
|
||||
expect(
|
||||
applyTrailingSlash(
|
||||
'https://xyz.com/abc/?search#anchor',
|
||||
params(undefined),
|
||||
),
|
||||
).toEqual('https://xyz.com/abc/?search#anchor');
|
||||
).toBe('https://xyz.com/abc/?search#anchor');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -67,28 +67,28 @@ describe('readOutputHTMLFile', () => {
|
|||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
undefined,
|
||||
).then(String),
|
||||
).resolves.toEqual('file\n');
|
||||
).resolves.toBe('file\n');
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/folder',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
undefined,
|
||||
).then(String),
|
||||
).resolves.toEqual('folder\n');
|
||||
).resolves.toBe('folder\n');
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/file/',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
undefined,
|
||||
).then(String),
|
||||
).resolves.toEqual('file\n');
|
||||
).resolves.toBe('file\n');
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/folder/',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
undefined,
|
||||
).then(String),
|
||||
).resolves.toEqual('folder\n');
|
||||
).resolves.toBe('folder\n');
|
||||
});
|
||||
it('trailing slash true', async () => {
|
||||
await expect(
|
||||
|
@ -97,14 +97,14 @@ describe('readOutputHTMLFile', () => {
|
|||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
true,
|
||||
).then(String),
|
||||
).resolves.toEqual('folder\n');
|
||||
).resolves.toBe('folder\n');
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/folder/',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
true,
|
||||
).then(String),
|
||||
).resolves.toEqual('folder\n');
|
||||
).resolves.toBe('folder\n');
|
||||
});
|
||||
it('trailing slash false', async () => {
|
||||
await expect(
|
||||
|
@ -113,14 +113,14 @@ describe('readOutputHTMLFile', () => {
|
|||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
false,
|
||||
).then(String),
|
||||
).resolves.toEqual('file\n');
|
||||
).resolves.toBe('file\n');
|
||||
await expect(
|
||||
readOutputHTMLFile(
|
||||
'/file/',
|
||||
path.join(__dirname, '__fixtures__/build-snap'),
|
||||
false,
|
||||
).then(String),
|
||||
).resolves.toEqual('file\n');
|
||||
).resolves.toBe('file\n');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -15,53 +15,53 @@ describe('createMatcher', () => {
|
|||
const matcher = createMatcher(GlobExcludeDefault);
|
||||
|
||||
it('match default exclude MD/MDX partials correctly', () => {
|
||||
expect(matcher('doc.md')).toEqual(false);
|
||||
expect(matcher('category/doc.md')).toEqual(false);
|
||||
expect(matcher('category/subcategory/doc.md')).toEqual(false);
|
||||
expect(matcher('doc.md')).toBe(false);
|
||||
expect(matcher('category/doc.md')).toBe(false);
|
||||
expect(matcher('category/subcategory/doc.md')).toBe(false);
|
||||
//
|
||||
expect(matcher('doc.mdx')).toEqual(false);
|
||||
expect(matcher('category/doc.mdx')).toEqual(false);
|
||||
expect(matcher('category/subcategory/doc.mdx')).toEqual(false);
|
||||
expect(matcher('doc.mdx')).toBe(false);
|
||||
expect(matcher('category/doc.mdx')).toBe(false);
|
||||
expect(matcher('category/subcategory/doc.mdx')).toBe(false);
|
||||
//
|
||||
expect(matcher('_doc.md')).toEqual(true);
|
||||
expect(matcher('category/_doc.md')).toEqual(true);
|
||||
expect(matcher('category/subcategory/_doc.md')).toEqual(true);
|
||||
expect(matcher('_category/doc.md')).toEqual(true);
|
||||
expect(matcher('_category/subcategory/doc.md')).toEqual(true);
|
||||
expect(matcher('category/_subcategory/doc.md')).toEqual(true);
|
||||
expect(matcher('_doc.md')).toBe(true);
|
||||
expect(matcher('category/_doc.md')).toBe(true);
|
||||
expect(matcher('category/subcategory/_doc.md')).toBe(true);
|
||||
expect(matcher('_category/doc.md')).toBe(true);
|
||||
expect(matcher('_category/subcategory/doc.md')).toBe(true);
|
||||
expect(matcher('category/_subcategory/doc.md')).toBe(true);
|
||||
});
|
||||
|
||||
it('match default exclude tests correctly', () => {
|
||||
expect(matcher('xyz.js')).toEqual(false);
|
||||
expect(matcher('xyz.ts')).toEqual(false);
|
||||
expect(matcher('xyz.jsx')).toEqual(false);
|
||||
expect(matcher('xyz.tsx')).toEqual(false);
|
||||
expect(matcher('folder/xyz.js')).toEqual(false);
|
||||
expect(matcher('folder/xyz.ts')).toEqual(false);
|
||||
expect(matcher('folder/xyz.jsx')).toEqual(false);
|
||||
expect(matcher('folder/xyz.tsx')).toEqual(false);
|
||||
expect(matcher('xyz.js')).toBe(false);
|
||||
expect(matcher('xyz.ts')).toBe(false);
|
||||
expect(matcher('xyz.jsx')).toBe(false);
|
||||
expect(matcher('xyz.tsx')).toBe(false);
|
||||
expect(matcher('folder/xyz.js')).toBe(false);
|
||||
expect(matcher('folder/xyz.ts')).toBe(false);
|
||||
expect(matcher('folder/xyz.jsx')).toBe(false);
|
||||
expect(matcher('folder/xyz.tsx')).toBe(false);
|
||||
//
|
||||
expect(matcher('xyz.test.js')).toEqual(true);
|
||||
expect(matcher('xyz.test.ts')).toEqual(true);
|
||||
expect(matcher('xyz.test.jsx')).toEqual(true);
|
||||
expect(matcher('xyz.test.tsx')).toEqual(true);
|
||||
expect(matcher('folder/xyz.test.js')).toEqual(true);
|
||||
expect(matcher('folder/xyz.test.ts')).toEqual(true);
|
||||
expect(matcher('folder/xyz.test.jsx')).toEqual(true);
|
||||
expect(matcher('folder/xyz.test.tsx')).toEqual(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.js')).toEqual(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.ts')).toEqual(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.jsx')).toEqual(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.tsx')).toEqual(true);
|
||||
expect(matcher('xyz.test.js')).toBe(true);
|
||||
expect(matcher('xyz.test.ts')).toBe(true);
|
||||
expect(matcher('xyz.test.jsx')).toBe(true);
|
||||
expect(matcher('xyz.test.tsx')).toBe(true);
|
||||
expect(matcher('folder/xyz.test.js')).toBe(true);
|
||||
expect(matcher('folder/xyz.test.ts')).toBe(true);
|
||||
expect(matcher('folder/xyz.test.jsx')).toBe(true);
|
||||
expect(matcher('folder/xyz.test.tsx')).toBe(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.js')).toBe(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.ts')).toBe(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.jsx')).toBe(true);
|
||||
expect(matcher('folder/subfolder/xyz.test.tsx')).toBe(true);
|
||||
//
|
||||
expect(matcher('__tests__/subfolder/xyz.js')).toEqual(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.ts')).toEqual(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.jsx')).toEqual(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.tsx')).toEqual(true);
|
||||
expect(matcher('folder/__tests__/xyz.js')).toEqual(true);
|
||||
expect(matcher('folder/__tests__/xyz.ts')).toEqual(true);
|
||||
expect(matcher('folder/__tests__/xyz.jsx')).toEqual(true);
|
||||
expect(matcher('folder/__tests__/xyz.tsx')).toEqual(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.js')).toBe(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.ts')).toBe(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.jsx')).toBe(true);
|
||||
expect(matcher('__tests__/subfolder/xyz.tsx')).toBe(true);
|
||||
expect(matcher('folder/__tests__/xyz.js')).toBe(true);
|
||||
expect(matcher('folder/__tests__/xyz.ts')).toBe(true);
|
||||
expect(matcher('folder/__tests__/xyz.jsx')).toBe(true);
|
||||
expect(matcher('folder/__tests__/xyz.tsx')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -74,29 +74,29 @@ describe('createAbsoluteFilePathMatcher', () => {
|
|||
);
|
||||
|
||||
it('match default exclude MD/MDX partials correctly', () => {
|
||||
expect(matcher('/_root/docs/myDoc.md')).toEqual(false);
|
||||
expect(matcher('/_root/docs/myDoc.mdx')).toEqual(false);
|
||||
expect(matcher('/root/_docs/myDoc.md')).toEqual(false);
|
||||
expect(matcher('/root/_docs/myDoc.mdx')).toEqual(false);
|
||||
expect(matcher('/_root/docs/category/myDoc.md')).toEqual(false);
|
||||
expect(matcher('/_root/docs/category/myDoc.mdx')).toEqual(false);
|
||||
expect(matcher('/root/_docs/category/myDoc.md')).toEqual(false);
|
||||
expect(matcher('/root/_docs/category/myDoc.mdx')).toEqual(false);
|
||||
expect(matcher('/_root/docs/myDoc.md')).toBe(false);
|
||||
expect(matcher('/_root/docs/myDoc.mdx')).toBe(false);
|
||||
expect(matcher('/root/_docs/myDoc.md')).toBe(false);
|
||||
expect(matcher('/root/_docs/myDoc.mdx')).toBe(false);
|
||||
expect(matcher('/_root/docs/category/myDoc.md')).toBe(false);
|
||||
expect(matcher('/_root/docs/category/myDoc.mdx')).toBe(false);
|
||||
expect(matcher('/root/_docs/category/myDoc.md')).toBe(false);
|
||||
expect(matcher('/root/_docs/category/myDoc.mdx')).toBe(false);
|
||||
//
|
||||
expect(matcher('/_root/docs/_myDoc.md')).toEqual(true);
|
||||
expect(matcher('/_root/docs/_myDoc.mdx')).toEqual(true);
|
||||
expect(matcher('/root/_docs/_myDoc.md')).toEqual(true);
|
||||
expect(matcher('/root/_docs/_myDoc.mdx')).toEqual(true);
|
||||
expect(matcher('/_root/docs/_category/myDoc.md')).toEqual(true);
|
||||
expect(matcher('/_root/docs/_category/myDoc.mdx')).toEqual(true);
|
||||
expect(matcher('/root/_docs/_category/myDoc.md')).toEqual(true);
|
||||
expect(matcher('/root/_docs/_category/myDoc.mdx')).toEqual(true);
|
||||
expect(matcher('/_root/docs/_myDoc.md')).toBe(true);
|
||||
expect(matcher('/_root/docs/_myDoc.mdx')).toBe(true);
|
||||
expect(matcher('/root/_docs/_myDoc.md')).toBe(true);
|
||||
expect(matcher('/root/_docs/_myDoc.mdx')).toBe(true);
|
||||
expect(matcher('/_root/docs/_category/myDoc.md')).toBe(true);
|
||||
expect(matcher('/_root/docs/_category/myDoc.mdx')).toBe(true);
|
||||
expect(matcher('/root/_docs/_category/myDoc.md')).toBe(true);
|
||||
expect(matcher('/root/_docs/_category/myDoc.mdx')).toBe(true);
|
||||
});
|
||||
|
||||
it('match default exclude tests correctly', () => {
|
||||
expect(matcher('/__test__/website/src/xyz.js')).toEqual(false);
|
||||
expect(matcher('/__test__/website/src/__test__/xyz.js')).toEqual(true);
|
||||
expect(matcher('/__test__/website/src/xyz.test.js')).toEqual(true);
|
||||
expect(matcher('/__test__/website/src/xyz.js')).toBe(false);
|
||||
expect(matcher('/__test__/website/src/__test__/xyz.js')).toBe(true);
|
||||
expect(matcher('/__test__/website/src/xyz.test.js')).toBe(true);
|
||||
});
|
||||
|
||||
it('throw if file is not contained in any root doc', () => {
|
||||
|
|
|
@ -18,23 +18,23 @@ import _ from 'lodash';
|
|||
|
||||
describe('removeSuffix', () => {
|
||||
it("is no-op when suffix doesn't exist", () => {
|
||||
expect(removeSuffix('abcdef', 'ijk')).toEqual('abcdef');
|
||||
expect(removeSuffix('abcdef', 'abc')).toEqual('abcdef');
|
||||
expect(removeSuffix('abcdef', '')).toEqual('abcdef');
|
||||
expect(removeSuffix('abcdef', 'ijk')).toBe('abcdef');
|
||||
expect(removeSuffix('abcdef', 'abc')).toBe('abcdef');
|
||||
expect(removeSuffix('abcdef', '')).toBe('abcdef');
|
||||
});
|
||||
it('removes suffix', () => {
|
||||
expect(removeSuffix('abcdef', 'ef')).toEqual('abcd');
|
||||
expect(removeSuffix('abcdef', 'ef')).toBe('abcd');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removePrefix', () => {
|
||||
it("is no-op when prefix doesn't exist", () => {
|
||||
expect(removePrefix('abcdef', 'ijk')).toEqual('abcdef');
|
||||
expect(removePrefix('abcdef', 'def')).toEqual('abcdef');
|
||||
expect(removePrefix('abcdef', '')).toEqual('abcdef');
|
||||
expect(removePrefix('abcdef', 'ijk')).toBe('abcdef');
|
||||
expect(removePrefix('abcdef', 'def')).toBe('abcdef');
|
||||
expect(removePrefix('abcdef', '')).toBe('abcdef');
|
||||
});
|
||||
it('removes prefix', () => {
|
||||
expect(removePrefix('abcdef', 'ab')).toEqual('cdef');
|
||||
expect(removePrefix('abcdef', 'ab')).toBe('cdef');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -133,7 +133,7 @@ describe('findAsyncSequential', () => {
|
|||
});
|
||||
|
||||
const timeBefore = Date.now();
|
||||
await expect(findAsyncSequential(items, findFn)).resolves.toEqual('2');
|
||||
await expect(findAsyncSequential(items, findFn)).resolves.toBe('2');
|
||||
const timeAfter = Date.now();
|
||||
|
||||
expect(findFn).toHaveBeenCalledTimes(2);
|
||||
|
|
|
@ -21,7 +21,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual(
|
||||
).toBe(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
||||
);
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual(
|
||||
).toBe(
|
||||
// h1 title is skipped on purpose, because we don't want the page to have
|
||||
// SEO metadata title === description
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
||||
|
@ -54,7 +54,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual(
|
||||
).toBe(
|
||||
// h1 title is skipped on purpose, because we don't want the page to have
|
||||
// SEO metadata title === description
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
||||
|
@ -68,7 +68,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual('Lorem ipsum dolor sit amet');
|
||||
).toBe('Lorem ipsum dolor sit amet');
|
||||
});
|
||||
|
||||
it('creates excerpt for content beginning with blockquote', () => {
|
||||
|
@ -78,7 +78,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual('Lorem ipsum dolor sit amet');
|
||||
).toBe('Lorem ipsum dolor sit amet');
|
||||
});
|
||||
|
||||
it('creates excerpt for content beginning with image (eg. blog post)', () => {
|
||||
|
@ -86,7 +86,7 @@ describe('createExcerpt', () => {
|
|||
createExcerpt(dedent`
|
||||

|
||||
`),
|
||||
).toEqual('Lorem ipsum');
|
||||
).toBe('Lorem ipsum');
|
||||
});
|
||||
|
||||
it('creates excerpt for content beginning with admonitions', () => {
|
||||
|
@ -102,7 +102,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||
).toBe('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||
});
|
||||
|
||||
it('creates excerpt for content with imports/exports declarations and Markdown markup, as well as Emoji', () => {
|
||||
|
@ -120,7 +120,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
`),
|
||||
).toEqual(
|
||||
).toBe(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
||||
);
|
||||
});
|
||||
|
@ -130,7 +130,7 @@ describe('createExcerpt', () => {
|
|||
createExcerpt(dedent`
|
||||
## Markdown title {#my-anchor-id}
|
||||
`),
|
||||
).toEqual('Markdown title');
|
||||
).toBe('Markdown title');
|
||||
});
|
||||
|
||||
it('creates excerpt for content with various code blocks', () => {
|
||||
|
@ -143,7 +143,7 @@ describe('createExcerpt', () => {
|
|||
|
||||
Lorem \`ipsum\` dolor sit amet, consectetur \`adipiscing elit\`.
|
||||
`),
|
||||
).toEqual('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||
).toBe('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -123,9 +123,9 @@ describe('toMessageRelativeFilePath', () => {
|
|||
jest
|
||||
.spyOn(process, 'cwd')
|
||||
.mockImplementationOnce(() => path.join(__dirname, '..'));
|
||||
expect(
|
||||
toMessageRelativeFilePath(path.join(__dirname, 'foo/bar.js')),
|
||||
).toEqual('__tests__/foo/bar.js');
|
||||
expect(toMessageRelativeFilePath(path.join(__dirname, 'foo/bar.js'))).toBe(
|
||||
'__tests__/foo/bar.js',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -10,18 +10,18 @@ import {createSlugger} from '../slugger';
|
|||
describe('createSlugger', () => {
|
||||
it('can create unique slugs', () => {
|
||||
const slugger = createSlugger();
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue');
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toEqual('somevalue-2');
|
||||
expect(slugger.slug('Some$/vaLue$!^-1')).toEqual('somevalue-1-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toBe('somevalue');
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toBe('somevalue-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^')).toBe('somevalue-2');
|
||||
expect(slugger.slug('Some$/vaLue$!^-1')).toBe('somevalue-1-1');
|
||||
});
|
||||
|
||||
it('can create unique slugs respecting case', () => {
|
||||
const slugger = createSlugger();
|
||||
const opt = {maintainCase: true};
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue');
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toEqual('SomevaLue-2');
|
||||
expect(slugger.slug('Some$/vaLue$!^-1', opt)).toEqual('SomevaLue-1-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toBe('SomevaLue');
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toBe('SomevaLue-1');
|
||||
expect(slugger.slug('Some$/vaLue$!^', opt)).toBe('SomevaLue-2');
|
||||
expect(slugger.slug('Some$/vaLue$!^-1', opt)).toBe('SomevaLue-1-1');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -146,15 +146,15 @@ describe('getEditUrl', () => {
|
|||
it('returns right path', () => {
|
||||
expect(
|
||||
getEditUrl('foo/bar.md', 'https://github.com/facebook/docusaurus'),
|
||||
).toEqual('https://github.com/facebook/docusaurus/foo/bar.md');
|
||||
).toBe('https://github.com/facebook/docusaurus/foo/bar.md');
|
||||
expect(
|
||||
getEditUrl('foo/你好.md', 'https://github.com/facebook/docusaurus'),
|
||||
).toEqual('https://github.com/facebook/docusaurus/foo/你好.md');
|
||||
).toBe('https://github.com/facebook/docusaurus/foo/你好.md');
|
||||
});
|
||||
it('always returns valid URL', () => {
|
||||
expect(
|
||||
getEditUrl('foo\\你好.md', 'https://github.com/facebook/docusaurus'),
|
||||
).toEqual('https://github.com/facebook/docusaurus/foo/你好.md');
|
||||
).toBe('https://github.com/facebook/docusaurus/foo/你好.md');
|
||||
});
|
||||
it('returns undefined for undefined', () => {
|
||||
expect(getEditUrl('foo/bar.md')).toBeUndefined();
|
||||
|
@ -200,28 +200,28 @@ describe('isValidPathname', () => {
|
|||
|
||||
describe('addTrailingSlash', () => {
|
||||
it('is no-op for path with trailing slash', () => {
|
||||
expect(addTrailingSlash('/abcd/')).toEqual('/abcd/');
|
||||
expect(addTrailingSlash('/abcd/')).toBe('/abcd/');
|
||||
});
|
||||
it('adds / for path without trailing slash', () => {
|
||||
expect(addTrailingSlash('/abcd')).toEqual('/abcd/');
|
||||
expect(addTrailingSlash('/abcd')).toBe('/abcd/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('addLeadingSlash', () => {
|
||||
it('is no-op for path with leading slash', () => {
|
||||
expect(addLeadingSlash('/abc')).toEqual('/abc');
|
||||
expect(addLeadingSlash('/abc')).toBe('/abc');
|
||||
});
|
||||
it('adds / for path without leading slash', () => {
|
||||
expect(addLeadingSlash('abc')).toEqual('/abc');
|
||||
expect(addLeadingSlash('abc')).toBe('/abc');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeTrailingSlash', () => {
|
||||
it('is no-op for path without trailing slash', () => {
|
||||
expect(removeTrailingSlash('/abcd')).toEqual('/abcd');
|
||||
expect(removeTrailingSlash('/abcd')).toBe('/abcd');
|
||||
});
|
||||
it('removes / for path with trailing slash', () => {
|
||||
expect(removeTrailingSlash('/abcd/')).toEqual('/abcd');
|
||||
expect(removeTrailingSlash('/abcd/')).toBe('/abcd');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -229,21 +229,21 @@ describe('resolvePathname', () => {
|
|||
it('works', () => {
|
||||
// These tests are directly copied from https://github.com/mjackson/resolve-pathname/blob/master/modules/__tests__/resolvePathname-test.js
|
||||
// Maybe we want to wrap that logic in the future?
|
||||
expect(resolvePathname('c')).toEqual('c');
|
||||
expect(resolvePathname('c', 'a/b')).toEqual('a/c');
|
||||
expect(resolvePathname('/c', '/a/b')).toEqual('/c');
|
||||
expect(resolvePathname('', '/a/b')).toEqual('/a/b');
|
||||
expect(resolvePathname('../c', '/a/b')).toEqual('/c');
|
||||
expect(resolvePathname('c', '/a/b')).toEqual('/a/c');
|
||||
expect(resolvePathname('c', '/a/')).toEqual('/a/c');
|
||||
expect(resolvePathname('..', '/a/b')).toEqual('/');
|
||||
expect(resolvePathname('c')).toBe('c');
|
||||
expect(resolvePathname('c', 'a/b')).toBe('a/c');
|
||||
expect(resolvePathname('/c', '/a/b')).toBe('/c');
|
||||
expect(resolvePathname('', '/a/b')).toBe('/a/b');
|
||||
expect(resolvePathname('../c', '/a/b')).toBe('/c');
|
||||
expect(resolvePathname('c', '/a/b')).toBe('/a/c');
|
||||
expect(resolvePathname('c', '/a/')).toBe('/a/c');
|
||||
expect(resolvePathname('..', '/a/b')).toBe('/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('encodePath', () => {
|
||||
it('works', () => {
|
||||
expect(encodePath('a/foo/')).toEqual('a/foo/');
|
||||
expect(encodePath('a/<foo>/')).toEqual('a/%3Cfoo%3E/');
|
||||
expect(encodePath('a/你好/')).toEqual('a/%E4%BD%A0%E5%A5%BD/');
|
||||
expect(encodePath('a/foo/')).toBe('a/foo/');
|
||||
expect(encodePath('a/<foo>/')).toBe('a/%3Cfoo%3E/');
|
||||
expect(encodePath('a/你好/')).toBe('a/%E4%BD%A0%E5%A5%BD/');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,15 +9,15 @@ import {translate} from '../Translate';
|
|||
|
||||
describe('translate', () => {
|
||||
it('accept id and use it as fallback', () => {
|
||||
expect(translate({id: 'some-id'})).toEqual('some-id');
|
||||
expect(translate({id: 'some-id'})).toBe('some-id');
|
||||
});
|
||||
|
||||
it('accept message and use it as fallback', () => {
|
||||
expect(translate({message: 'some-message'})).toEqual('some-message');
|
||||
expect(translate({message: 'some-message'})).toBe('some-message');
|
||||
});
|
||||
|
||||
it('accept id+message and use message as fallback', () => {
|
||||
expect(translate({id: 'some-id', message: 'some-message'})).toEqual(
|
||||
expect(translate({id: 'some-id', message: 'some-message'})).toBe(
|
||||
'some-message',
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
/**
|
||||
* 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 {jest} from '@jest/globals';
|
||||
import useBaseUrl, {useBaseUrlUtils} from '../useBaseUrl';
|
||||
import useDocusaurusContext from '../useDocusaurusContext';
|
||||
|
||||
jest.mock('../useDocusaurusContext');
|
||||
|
||||
const mockedContext = useDocusaurusContext as jest.Mock;
|
||||
|
||||
const forcePrepend = {forcePrependBaseUrl: true};
|
||||
|
||||
describe('useBaseUrl', () => {
|
||||
it('empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
}));
|
||||
|
||||
expect(useBaseUrl('hello')).toEqual('/hello');
|
||||
expect(useBaseUrl('/hello')).toEqual('/hello');
|
||||
expect(useBaseUrl('hello/')).toEqual('/hello/');
|
||||
expect(useBaseUrl('/hello/')).toEqual('/hello/');
|
||||
expect(useBaseUrl('hello/byebye')).toEqual('/hello/byebye');
|
||||
expect(useBaseUrl('/hello/byebye')).toEqual('/hello/byebye');
|
||||
expect(useBaseUrl('hello/byebye/')).toEqual('/hello/byebye/');
|
||||
expect(useBaseUrl('/hello/byebye/')).toEqual('/hello/byebye/');
|
||||
expect(useBaseUrl('https://github.com')).toEqual('https://github.com');
|
||||
expect(useBaseUrl('//reactjs.org')).toEqual('//reactjs.org');
|
||||
expect(useBaseUrl('//reactjs.org', forcePrepend)).toEqual('//reactjs.org');
|
||||
expect(useBaseUrl('https://site.com', forcePrepend)).toEqual(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(useBaseUrl('/hello/byebye', {absolute: true})).toEqual(
|
||||
'https://docusaurus.io/hello/byebye',
|
||||
);
|
||||
expect(useBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
|
||||
it('non-empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
}));
|
||||
|
||||
expect(useBaseUrl('')).toEqual('');
|
||||
expect(useBaseUrl('hello')).toEqual('/docusaurus/hello');
|
||||
expect(useBaseUrl('/hello')).toEqual('/docusaurus/hello');
|
||||
expect(useBaseUrl('hello/')).toEqual('/docusaurus/hello/');
|
||||
expect(useBaseUrl('/hello/')).toEqual('/docusaurus/hello/');
|
||||
expect(useBaseUrl('hello/byebye')).toEqual('/docusaurus/hello/byebye');
|
||||
expect(useBaseUrl('/hello/byebye')).toEqual('/docusaurus/hello/byebye');
|
||||
expect(useBaseUrl('hello/byebye/')).toEqual('/docusaurus/hello/byebye/');
|
||||
expect(useBaseUrl('/hello/byebye/')).toEqual('/docusaurus/hello/byebye/');
|
||||
expect(useBaseUrl('https://github.com')).toEqual('https://github.com');
|
||||
expect(useBaseUrl('//reactjs.org')).toEqual('//reactjs.org');
|
||||
expect(useBaseUrl('//reactjs.org', forcePrepend)).toEqual('//reactjs.org');
|
||||
expect(useBaseUrl('/hello', forcePrepend)).toEqual('/docusaurus/hello');
|
||||
expect(useBaseUrl('https://site.com', forcePrepend)).toEqual(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(useBaseUrl('/hello/byebye', {absolute: true})).toEqual(
|
||||
'https://docusaurus.io/docusaurus/hello/byebye',
|
||||
);
|
||||
expect(useBaseUrl('/docusaurus/')).toEqual('/docusaurus/');
|
||||
expect(useBaseUrl('/docusaurus/hello')).toEqual('/docusaurus/hello');
|
||||
expect(useBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useBaseUrlUtils().withBaseUrl()', () => {
|
||||
it('empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
}));
|
||||
const {withBaseUrl} = useBaseUrlUtils();
|
||||
|
||||
expect(withBaseUrl('hello')).toEqual('/hello');
|
||||
expect(withBaseUrl('/hello')).toEqual('/hello');
|
||||
expect(withBaseUrl('hello/')).toEqual('/hello/');
|
||||
expect(withBaseUrl('/hello/')).toEqual('/hello/');
|
||||
expect(withBaseUrl('hello/byebye')).toEqual('/hello/byebye');
|
||||
expect(withBaseUrl('/hello/byebye')).toEqual('/hello/byebye');
|
||||
expect(withBaseUrl('hello/byebye/')).toEqual('/hello/byebye/');
|
||||
expect(withBaseUrl('/hello/byebye/')).toEqual('/hello/byebye/');
|
||||
expect(withBaseUrl('https://github.com')).toEqual('https://github.com');
|
||||
expect(withBaseUrl('//reactjs.org')).toEqual('//reactjs.org');
|
||||
expect(withBaseUrl('//reactjs.org', forcePrepend)).toEqual('//reactjs.org');
|
||||
expect(withBaseUrl('https://site.com', forcePrepend)).toEqual(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(withBaseUrl('/hello/byebye', {absolute: true})).toEqual(
|
||||
'https://docusaurus.io/hello/byebye',
|
||||
);
|
||||
expect(withBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
|
||||
it('non-empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
}));
|
||||
const {withBaseUrl} = useBaseUrlUtils();
|
||||
|
||||
expect(withBaseUrl('hello')).toEqual('/docusaurus/hello');
|
||||
expect(withBaseUrl('/hello')).toEqual('/docusaurus/hello');
|
||||
expect(withBaseUrl('hello/')).toEqual('/docusaurus/hello/');
|
||||
expect(withBaseUrl('/hello/')).toEqual('/docusaurus/hello/');
|
||||
expect(withBaseUrl('hello/byebye')).toEqual('/docusaurus/hello/byebye');
|
||||
expect(withBaseUrl('/hello/byebye')).toEqual('/docusaurus/hello/byebye');
|
||||
expect(withBaseUrl('hello/byebye/')).toEqual('/docusaurus/hello/byebye/');
|
||||
expect(withBaseUrl('/hello/byebye/')).toEqual('/docusaurus/hello/byebye/');
|
||||
expect(withBaseUrl('https://github.com')).toEqual('https://github.com');
|
||||
expect(withBaseUrl('//reactjs.org')).toEqual('//reactjs.org');
|
||||
expect(withBaseUrl('//reactjs.org', forcePrepend)).toEqual('//reactjs.org');
|
||||
expect(withBaseUrl('https://site.com', forcePrepend)).toEqual(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(withBaseUrl('/hello/byebye', {absolute: true})).toEqual(
|
||||
'https://docusaurus.io/docusaurus/hello/byebye',
|
||||
);
|
||||
expect(withBaseUrl('/docusaurus/')).toEqual('/docusaurus/');
|
||||
expect(withBaseUrl('/docusaurus/hello')).toEqual('/docusaurus/hello');
|
||||
expect(withBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,150 @@
|
|||
/**
|
||||
* 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 React from 'react';
|
||||
import {renderHook} from '@testing-library/react-hooks';
|
||||
import useBaseUrl, {useBaseUrlUtils} from '../useBaseUrl';
|
||||
import {Context} from '../docusaurusContext';
|
||||
import type {DocusaurusContext} from '@docusaurus/types';
|
||||
import type {BaseUrlOptions} from '@docusaurus/useBaseUrl';
|
||||
|
||||
const forcePrepend = {forcePrependBaseUrl: true};
|
||||
|
||||
describe('useBaseUrl', () => {
|
||||
const createUseBaseUrlMock =
|
||||
(context: DocusaurusContext) => (url: string, options?: BaseUrlOptions) =>
|
||||
renderHook(() => useBaseUrl(url, options), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>{children}</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('works with empty base URL', () => {
|
||||
const mockUseBaseUrl = createUseBaseUrlMock({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockUseBaseUrl('hello')).toBe('/hello');
|
||||
expect(mockUseBaseUrl('/hello')).toBe('/hello');
|
||||
expect(mockUseBaseUrl('hello/')).toBe('/hello/');
|
||||
expect(mockUseBaseUrl('/hello/')).toBe('/hello/');
|
||||
expect(mockUseBaseUrl('hello/byebye')).toBe('/hello/byebye');
|
||||
expect(mockUseBaseUrl('/hello/byebye')).toBe('/hello/byebye');
|
||||
expect(mockUseBaseUrl('hello/byebye/')).toBe('/hello/byebye/');
|
||||
expect(mockUseBaseUrl('/hello/byebye/')).toBe('/hello/byebye/');
|
||||
expect(mockUseBaseUrl('https://github.com')).toBe('https://github.com');
|
||||
expect(mockUseBaseUrl('//reactjs.org')).toBe('//reactjs.org');
|
||||
expect(mockUseBaseUrl('//reactjs.org', forcePrepend)).toBe('//reactjs.org');
|
||||
expect(mockUseBaseUrl('https://site.com', forcePrepend)).toBe(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(mockUseBaseUrl('/hello/byebye', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/hello/byebye',
|
||||
);
|
||||
expect(mockUseBaseUrl('#hello')).toBe('#hello');
|
||||
});
|
||||
|
||||
it('works with non-empty base URL', () => {
|
||||
const mockUseBaseUrl = createUseBaseUrlMock({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockUseBaseUrl('')).toBe('');
|
||||
expect(mockUseBaseUrl('hello')).toBe('/docusaurus/hello');
|
||||
expect(mockUseBaseUrl('/hello')).toBe('/docusaurus/hello');
|
||||
expect(mockUseBaseUrl('hello/')).toBe('/docusaurus/hello/');
|
||||
expect(mockUseBaseUrl('/hello/')).toBe('/docusaurus/hello/');
|
||||
expect(mockUseBaseUrl('hello/byebye')).toBe('/docusaurus/hello/byebye');
|
||||
expect(mockUseBaseUrl('/hello/byebye')).toBe('/docusaurus/hello/byebye');
|
||||
expect(mockUseBaseUrl('hello/byebye/')).toBe('/docusaurus/hello/byebye/');
|
||||
expect(mockUseBaseUrl('/hello/byebye/')).toBe('/docusaurus/hello/byebye/');
|
||||
expect(mockUseBaseUrl('https://github.com')).toBe('https://github.com');
|
||||
expect(mockUseBaseUrl('//reactjs.org')).toBe('//reactjs.org');
|
||||
expect(mockUseBaseUrl('//reactjs.org', forcePrepend)).toBe('//reactjs.org');
|
||||
expect(mockUseBaseUrl('/hello', forcePrepend)).toBe('/docusaurus/hello');
|
||||
expect(mockUseBaseUrl('https://site.com', forcePrepend)).toBe(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(mockUseBaseUrl('/hello/byebye', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/docusaurus/hello/byebye',
|
||||
);
|
||||
expect(mockUseBaseUrl('/docusaurus/')).toBe('/docusaurus/');
|
||||
expect(mockUseBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
|
||||
expect(mockUseBaseUrl('#hello')).toBe('#hello');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useBaseUrlUtils().withBaseUrl()', () => {
|
||||
const mockUseBaseUrlUtils = (context: DocusaurusContext) =>
|
||||
renderHook(() => useBaseUrlUtils(), {
|
||||
wrapper: ({children}) => (
|
||||
<Context.Provider value={context}>{children}</Context.Provider>
|
||||
),
|
||||
}).result.current;
|
||||
it('empty base URL', () => {
|
||||
const {withBaseUrl} = mockUseBaseUrlUtils({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
});
|
||||
|
||||
expect(withBaseUrl('hello')).toBe('/hello');
|
||||
expect(withBaseUrl('/hello')).toBe('/hello');
|
||||
expect(withBaseUrl('hello/')).toBe('/hello/');
|
||||
expect(withBaseUrl('/hello/')).toBe('/hello/');
|
||||
expect(withBaseUrl('hello/byebye')).toBe('/hello/byebye');
|
||||
expect(withBaseUrl('/hello/byebye')).toBe('/hello/byebye');
|
||||
expect(withBaseUrl('hello/byebye/')).toBe('/hello/byebye/');
|
||||
expect(withBaseUrl('/hello/byebye/')).toBe('/hello/byebye/');
|
||||
expect(withBaseUrl('https://github.com')).toBe('https://github.com');
|
||||
expect(withBaseUrl('//reactjs.org')).toBe('//reactjs.org');
|
||||
expect(withBaseUrl('//reactjs.org', forcePrepend)).toBe('//reactjs.org');
|
||||
expect(withBaseUrl('https://site.com', forcePrepend)).toBe(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(withBaseUrl('/hello/byebye', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/hello/byebye',
|
||||
);
|
||||
expect(withBaseUrl('#hello')).toBe('#hello');
|
||||
});
|
||||
|
||||
it('non-empty base URL', () => {
|
||||
const {withBaseUrl} = mockUseBaseUrlUtils({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
url: 'https://docusaurus.io',
|
||||
},
|
||||
});
|
||||
|
||||
expect(withBaseUrl('hello')).toBe('/docusaurus/hello');
|
||||
expect(withBaseUrl('/hello')).toBe('/docusaurus/hello');
|
||||
expect(withBaseUrl('hello/')).toBe('/docusaurus/hello/');
|
||||
expect(withBaseUrl('/hello/')).toBe('/docusaurus/hello/');
|
||||
expect(withBaseUrl('hello/byebye')).toBe('/docusaurus/hello/byebye');
|
||||
expect(withBaseUrl('/hello/byebye')).toBe('/docusaurus/hello/byebye');
|
||||
expect(withBaseUrl('hello/byebye/')).toBe('/docusaurus/hello/byebye/');
|
||||
expect(withBaseUrl('/hello/byebye/')).toBe('/docusaurus/hello/byebye/');
|
||||
expect(withBaseUrl('https://github.com')).toBe('https://github.com');
|
||||
expect(withBaseUrl('//reactjs.org')).toBe('//reactjs.org');
|
||||
expect(withBaseUrl('//reactjs.org', forcePrepend)).toBe('//reactjs.org');
|
||||
expect(withBaseUrl('https://site.com', forcePrepend)).toBe(
|
||||
'https://site.com',
|
||||
);
|
||||
expect(withBaseUrl('/hello/byebye', {absolute: true})).toBe(
|
||||
'https://docusaurus.io/docusaurus/hello/byebye',
|
||||
);
|
||||
expect(withBaseUrl('/docusaurus/')).toBe('/docusaurus/');
|
||||
expect(withBaseUrl('/docusaurus/hello')).toBe('/docusaurus/hello');
|
||||
expect(withBaseUrl('#hello')).toBe('#hello');
|
||||
});
|
||||
});
|
|
@ -10,11 +10,11 @@ import {buildSshUrl, buildHttpsUrl, hasSSHProtocol} from '../deploy';
|
|||
describe('remoteBranchUrl', () => {
|
||||
it('builds a normal ssh url', () => {
|
||||
const url = buildSshUrl('github.com', 'facebook', 'docusaurus');
|
||||
expect(url).toEqual('git@github.com:facebook/docusaurus.git');
|
||||
expect(url).toBe('git@github.com:facebook/docusaurus.git');
|
||||
});
|
||||
it('builds a ssh url with port', () => {
|
||||
const url = buildSshUrl('github.com', 'facebook', 'docusaurus', '422');
|
||||
expect(url).toEqual('ssh://git@github.com:422/facebook/docusaurus.git');
|
||||
expect(url).toBe('ssh://git@github.com:422/facebook/docusaurus.git');
|
||||
});
|
||||
it('builds a normal http url', () => {
|
||||
const url = buildHttpsUrl(
|
||||
|
@ -23,7 +23,7 @@ describe('remoteBranchUrl', () => {
|
|||
'facebook',
|
||||
'docusaurus',
|
||||
);
|
||||
expect(url).toEqual('https://user:pass@github.com/facebook/docusaurus.git');
|
||||
expect(url).toBe('https://user:pass@github.com/facebook/docusaurus.git');
|
||||
});
|
||||
it('builds a normal http url with port', () => {
|
||||
const url = buildHttpsUrl(
|
||||
|
@ -33,7 +33,7 @@ describe('remoteBranchUrl', () => {
|
|||
'docusaurus',
|
||||
'5433',
|
||||
);
|
||||
expect(url).toEqual(
|
||||
expect(url).toBe(
|
||||
'https://user:pass@github.com:5433/facebook/docusaurus.git',
|
||||
);
|
||||
});
|
||||
|
@ -42,21 +42,21 @@ describe('remoteBranchUrl', () => {
|
|||
describe('hasSSHProtocol', () => {
|
||||
it('recognizes explicit SSH protocol', () => {
|
||||
const url = 'ssh://git@github.com:422/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(true);
|
||||
expect(hasSSHProtocol(url)).toBe(true);
|
||||
});
|
||||
|
||||
it('recognizes implied SSH protocol', () => {
|
||||
const url = 'git@github.com:facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(true);
|
||||
expect(hasSSHProtocol(url)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not recognize HTTPS with credentials', () => {
|
||||
const url = 'https://user:pass@github.com/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(false);
|
||||
expect(hasSSHProtocol(url)).toBe(false);
|
||||
});
|
||||
|
||||
it('does not recognize plain HTTPS URL', () => {
|
||||
const url = 'https://github.com:5433/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(false);
|
||||
expect(hasSSHProtocol(url)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,39 +9,39 @@ import {transformMarkdownContent} from '../writeHeadingIds';
|
|||
|
||||
describe('transformMarkdownContent', () => {
|
||||
it('works for simple level-2 heading', () => {
|
||||
expect(transformMarkdownContent('## ABC')).toEqual('## ABC {#abc}');
|
||||
expect(transformMarkdownContent('## ABC')).toBe('## ABC {#abc}');
|
||||
});
|
||||
|
||||
it('works for simple level-3 heading', () => {
|
||||
expect(transformMarkdownContent('### ABC')).toEqual('### ABC {#abc}');
|
||||
expect(transformMarkdownContent('### ABC')).toBe('### ABC {#abc}');
|
||||
});
|
||||
|
||||
it('works for simple level-4 heading', () => {
|
||||
expect(transformMarkdownContent('#### ABC')).toEqual('#### ABC {#abc}');
|
||||
expect(transformMarkdownContent('#### ABC')).toBe('#### ABC {#abc}');
|
||||
});
|
||||
|
||||
it('unwraps markdown links', () => {
|
||||
const input = `## hello [facebook](https://facebook.com) [crowdin](https://crowdin.com/translate/docusaurus-v2/126/en-fr?filter=basic&value=0)`;
|
||||
expect(transformMarkdownContent(input)).toEqual(
|
||||
expect(transformMarkdownContent(input)).toBe(
|
||||
`${input} {#hello-facebook-crowdin}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('can slugify complex headings', () => {
|
||||
const input = '## abc [Hello] How are you %Sébastien_-_$)( ## -56756';
|
||||
expect(transformMarkdownContent(input)).toEqual(
|
||||
expect(transformMarkdownContent(input)).toBe(
|
||||
`${input} {#abc-hello-how-are-you-sébastien_-_---56756}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('does not duplicate duplicate id', () => {
|
||||
expect(transformMarkdownContent('## hello world {#hello-world}')).toEqual(
|
||||
expect(transformMarkdownContent('## hello world {#hello-world}')).toBe(
|
||||
'## hello world {#hello-world}',
|
||||
);
|
||||
});
|
||||
|
||||
it('respects existing heading', () => {
|
||||
expect(transformMarkdownContent('## New heading {#old-heading}')).toEqual(
|
||||
expect(transformMarkdownContent('## New heading {#old-heading}')).toBe(
|
||||
'## New heading {#old-heading}',
|
||||
);
|
||||
});
|
||||
|
@ -51,7 +51,7 @@ describe('transformMarkdownContent', () => {
|
|||
transformMarkdownContent('## New heading {#old-heading}', {
|
||||
overwrite: true,
|
||||
}),
|
||||
).toEqual('## New heading {#new-heading}');
|
||||
).toBe('## New heading {#new-heading}');
|
||||
});
|
||||
|
||||
it('maintains casing when asked to', () => {
|
||||
|
@ -59,7 +59,7 @@ describe('transformMarkdownContent', () => {
|
|||
transformMarkdownContent('## getDataFromAPI()', {
|
||||
maintainCase: true,
|
||||
}),
|
||||
).toEqual('## getDataFromAPI() {#getDataFromAPI}');
|
||||
).toBe('## getDataFromAPI() {#getDataFromAPI}');
|
||||
});
|
||||
|
||||
it('transform the headings', () => {
|
||||
|
|
|
@ -118,15 +118,15 @@ describe('getThemeComponents', () => {
|
|||
themePath,
|
||||
swizzleConfig,
|
||||
});
|
||||
expect(
|
||||
themeComponents.getDescription(Components.ComponentInFolder),
|
||||
).toEqual('ComponentInFolder description');
|
||||
expect(themeComponents.getDescription(Components.ComponentInFolder)).toBe(
|
||||
'ComponentInFolder description',
|
||||
);
|
||||
expect(
|
||||
themeComponents.getDescription(Components.ComponentInSubFolder),
|
||||
).toEqual('N/A');
|
||||
expect(
|
||||
themeComponents.getDescription(Components.FirstLevelComponent),
|
||||
).toEqual('N/A');
|
||||
).toBe('N/A');
|
||||
expect(themeComponents.getDescription(Components.FirstLevelComponent)).toBe(
|
||||
'N/A',
|
||||
);
|
||||
});
|
||||
|
||||
it('getActionStatus', async () => {
|
||||
|
@ -137,24 +137,24 @@ describe('getThemeComponents', () => {
|
|||
});
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.ComponentInFolder, 'wrap'),
|
||||
).toEqual('safe');
|
||||
).toBe('safe');
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.ComponentInFolder, 'eject'),
|
||||
).toEqual('unsafe');
|
||||
).toBe('unsafe');
|
||||
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.ComponentInSubFolder, 'wrap'),
|
||||
).toEqual('unsafe');
|
||||
).toBe('unsafe');
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.ComponentInSubFolder, 'eject'),
|
||||
).toEqual('safe');
|
||||
).toBe('safe');
|
||||
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.FirstLevelComponent, 'wrap'),
|
||||
).toEqual('unsafe');
|
||||
).toBe('unsafe');
|
||||
expect(
|
||||
themeComponents.getActionStatus(Components.FirstLevelComponent, 'eject'),
|
||||
).toEqual('unsafe');
|
||||
).toBe('unsafe');
|
||||
});
|
||||
|
||||
it('isSafeAction', async () => {
|
||||
|
@ -165,24 +165,24 @@ describe('getThemeComponents', () => {
|
|||
});
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.ComponentInFolder, 'wrap'),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.ComponentInFolder, 'eject'),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.ComponentInSubFolder, 'wrap'),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.ComponentInSubFolder, 'eject'),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.FirstLevelComponent, 'wrap'),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
expect(
|
||||
themeComponents.isSafeAction(Components.FirstLevelComponent, 'eject'),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('hasAnySafeAction', async () => {
|
||||
|
@ -191,14 +191,14 @@ describe('getThemeComponents', () => {
|
|||
themePath,
|
||||
swizzleConfig,
|
||||
});
|
||||
expect(
|
||||
themeComponents.hasAnySafeAction(Components.ComponentInFolder),
|
||||
).toEqual(true);
|
||||
expect(themeComponents.hasAnySafeAction(Components.ComponentInFolder)).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
themeComponents.hasAnySafeAction(Components.ComponentInSubFolder),
|
||||
).toEqual(true);
|
||||
).toBe(true);
|
||||
expect(
|
||||
themeComponents.hasAnySafeAction(Components.FirstLevelComponent),
|
||||
).toEqual(false);
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -287,8 +287,8 @@ describe('config warnings', () => {
|
|||
url: 'https://mysite.com/someSubpath',
|
||||
});
|
||||
expect(warning).toBeDefined();
|
||||
expect(warning?.details.length).toEqual(1);
|
||||
expect(warning?.details[0].message).toMatchInlineSnapshot(
|
||||
expect(warning.details).toHaveLength(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"`,
|
||||
);
|
||||
});
|
||||
|
|
|
@ -181,7 +181,7 @@ describe('localizePath', () => {
|
|||
},
|
||||
options: {localizePath: true},
|
||||
}),
|
||||
).toEqual('/baseUrl/fr/');
|
||||
).toBe('/baseUrl/fr/');
|
||||
});
|
||||
|
||||
it('localizes fs path with current locale', () => {
|
||||
|
@ -197,7 +197,7 @@ describe('localizePath', () => {
|
|||
},
|
||||
options: {localizePath: true},
|
||||
}),
|
||||
).toEqual(`${path.sep}baseFsPath${path.sep}fr`);
|
||||
).toBe(`${path.sep}baseFsPath${path.sep}fr`);
|
||||
});
|
||||
|
||||
it('localizes path for default locale, if requested', () => {
|
||||
|
@ -213,7 +213,7 @@ describe('localizePath', () => {
|
|||
},
|
||||
options: {localizePath: true},
|
||||
}),
|
||||
).toEqual('/baseUrl/en/');
|
||||
).toBe('/baseUrl/en/');
|
||||
});
|
||||
|
||||
it('does not localize path for default locale by default', () => {
|
||||
|
@ -229,7 +229,7 @@ describe('localizePath', () => {
|
|||
},
|
||||
// options: {localizePath: true},
|
||||
}),
|
||||
).toEqual('/baseUrl/');
|
||||
).toBe('/baseUrl/');
|
||||
});
|
||||
|
||||
it('localizes path for non-default locale by default', () => {
|
||||
|
@ -245,6 +245,6 @@ describe('localizePath', () => {
|
|||
},
|
||||
// options: {localizePath: true},
|
||||
}),
|
||||
).toEqual('/baseUrl/');
|
||||
).toBe('/baseUrl/');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`initPlugins plugins with bad values throw user-friendly error message 1`] = `
|
||||
exports[`initPlugins throws user-friendly error message for plugins with bad values 1`] = `
|
||||
" => Bad Docusaurus plugin value as path [plugins,0].
|
||||
Example valid plugin config:
|
||||
{
|
||||
|
|
|
@ -29,10 +29,10 @@ describe('initPlugins', () => {
|
|||
return {siteDir, context, plugins};
|
||||
}
|
||||
|
||||
it('plugins gets parsed correctly and loads in correct order', async () => {
|
||||
it('parses plugins correctly and loads them in correct order', async () => {
|
||||
const {context, plugins} = await loadSite();
|
||||
expect(context.siteConfig.plugins?.length).toBe(4);
|
||||
expect(plugins.length).toBe(8);
|
||||
expect(plugins).toHaveLength(8);
|
||||
|
||||
expect(plugins[0].name).toBe('preset-plugin1');
|
||||
expect(plugins[1].name).toBe('preset-plugin2');
|
||||
|
@ -45,7 +45,7 @@ describe('initPlugins', () => {
|
|||
expect(context.siteConfig.themeConfig).toEqual({a: 1});
|
||||
});
|
||||
|
||||
it('plugins with bad values throw user-friendly error message', async () => {
|
||||
it('throws user-friendly error message for plugins with bad values', async () => {
|
||||
await expect(() =>
|
||||
loadSite({
|
||||
customConfigFilePath: 'badPlugins.docusaurus.config.js',
|
||||
|
|
|
@ -348,9 +348,7 @@ describe('writePluginTranslations', () => {
|
|||
});
|
||||
}
|
||||
|
||||
await expect(readTranslationFileContent(filePath)).resolves.toEqual(
|
||||
undefined,
|
||||
);
|
||||
await expect(readTranslationFileContent(filePath)).resolves.toBeUndefined();
|
||||
|
||||
await doWritePluginTranslations({
|
||||
key1: {message: 'key1 message', description: 'key1 desc'},
|
||||
|
|
|
@ -28,7 +28,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
path.join('exports', 'Link.js'),
|
||||
];
|
||||
clientFiles.forEach((file) => {
|
||||
expect(excludeJS(path.join(clientDir, file))).toEqual(false);
|
||||
expect(excludeJS(path.join(clientDir, file))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -39,7 +39,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
'/src/theme/SearchBar/index.js',
|
||||
];
|
||||
moduleFiles.forEach((file) => {
|
||||
expect(excludeJS(file)).toEqual(false);
|
||||
expect(excludeJS(file)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,7 +50,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
'/docusaurus/website/node_modules/@docusaurus/theme-search-algolia/theme/SearchBar.js',
|
||||
];
|
||||
moduleFiles.forEach((file) => {
|
||||
expect(excludeJS(file)).toEqual(false);
|
||||
expect(excludeJS(file)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -63,7 +63,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
'node_modules/docusaurus-theme-classic/node_modules/react-daypicker/index.js',
|
||||
];
|
||||
moduleFiles.forEach((file) => {
|
||||
expect(excludeJS(file)).toEqual(true);
|
||||
expect(excludeJS(file)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ import loadSetup from '../../server/__tests__/testUtils';
|
|||
|
||||
describe('webpack production config', () => {
|
||||
it('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
jest.spyOn(console, 'log').mockImplementation();
|
||||
const props = await loadSetup('simple');
|
||||
const config = await createServerConfig({props});
|
||||
const errors = webpack.validate(config);
|
||||
|
@ -21,7 +21,7 @@ describe('webpack production config', () => {
|
|||
});
|
||||
|
||||
it('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
jest.spyOn(console, 'log').mockImplementation();
|
||||
const props = await loadSetup('custom');
|
||||
const config = await createServerConfig({props});
|
||||
const errors = webpack.validate(config);
|
||||
|
|
|
@ -268,7 +268,7 @@ describe('extending PostCSS', () => {
|
|||
|
||||
// @ts-expect-error: relax type
|
||||
const postCssLoader1 = webpackConfig.module?.rules[0].use[2];
|
||||
expect(postCssLoader1.loader).toEqual('postcss-loader-1');
|
||||
expect(postCssLoader1.loader).toBe('postcss-loader-1');
|
||||
|
||||
const pluginNames1 = postCssLoader1.options.postcssOptions.plugins.map(
|
||||
(p: unknown) => p[0],
|
||||
|
@ -283,7 +283,7 @@ describe('extending PostCSS', () => {
|
|||
|
||||
// @ts-expect-error: relax type
|
||||
const postCssLoader2 = webpackConfig.module?.rules[1].use[0];
|
||||
expect(postCssLoader2.loader).toEqual('postcss-loader-2');
|
||||
expect(postCssLoader2.loader).toBe('postcss-loader-2');
|
||||
|
||||
const pluginNames2 = postCssLoader2.options.postcssOptions.plugins.map(
|
||||
(p: unknown) => p[0],
|
||||
|
|
|
@ -15,7 +15,7 @@ describe('toBase64', () => {
|
|||
it('returns a properly formatted Base64 image string', () => {
|
||||
const mockedMimeType = 'image/jpeg';
|
||||
const mockedBase64Data = Buffer.from('hello world');
|
||||
expect(toBase64(mockedMimeType, mockedBase64Data)).toEqual(
|
||||
expect(toBase64(mockedMimeType, mockedBase64Data)).toBe(
|
||||
'data:image/jpeg;base64,aGVsbG8gd29ybGQ=',
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue