mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
test: enable a few jest eslint rules (#6900)
* test: enable a few jest eslint rules * more
This commit is contained in:
parent
1efc6c6091
commit
aa5a2d4c04
155 changed files with 3644 additions and 3478 deletions
|
@ -1,26 +1,19 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
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[`sidebar site with undefined sidebar 1`] = `
|
||||
Object {
|
||||
"defaultSidebar": Array [
|
||||
Object {
|
||||
"id": "hello-1",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "hello-2",
|
||||
"label": "Hello 2 From Doc",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`simple website content 1`] = `
|
||||
|
@ -1247,6 +1240,15 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`simple website getPathToWatch 1`] = `
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
"docs/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`site with custom sidebar items generator sidebar is autogenerated according to a custom sidebarItemsGenerator 1`] = `
|
||||
Object {
|
||||
"defaultSidebar": Array [
|
||||
|
@ -2511,6 +2513,19 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`versioned website (community) getPathToWatch 1`] = `
|
||||
Array [
|
||||
"community_sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/current/**/*.{md,mdx}",
|
||||
"community/**/*.{md,mdx}",
|
||||
"community/**/_category_.{json,yml,yaml}",
|
||||
"community_versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/version-1.0.0/**/*.{md,mdx}",
|
||||
"community_versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"community_versioned_docs/version-1.0.0/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`versioned website content 1`] = `
|
||||
Object {
|
||||
"description": "This is next version of bar.",
|
||||
|
@ -3885,3 +3900,24 @@ Object {
|
|||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`versioned website getPathToWatch 1`] = `
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
"docs/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-1.0.1-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.1/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.0/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-withSlugs-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-withSlugs/**/*.{md,mdx}",
|
||||
"versioned_docs/version-withSlugs/**/*.{md,mdx}",
|
||||
"versioned_docs/version-withSlugs/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`getLoadedContentTranslationFiles should return translation files matching snapshot 1`] = `
|
||||
exports[`getLoadedContentTranslationFiles returns translation files 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"content": Object {
|
||||
|
@ -80,7 +80,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`translateLoadedContent should return translated loaded content matching snapshot 1`] = `
|
||||
exports[`translateLoadedContent returns translated loaded content 1`] = `
|
||||
Object {
|
||||
"loadedVersions": Array [
|
||||
Object {
|
||||
|
|
|
@ -33,7 +33,7 @@ describe('docsVersion', () => {
|
|||
sidebarCollapsible: true,
|
||||
};
|
||||
|
||||
test('no version tag provided', async () => {
|
||||
it('no version tag provided', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
null,
|
||||
|
@ -66,7 +66,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('version tag should not have slash', async () => {
|
||||
it('version tag should not have slash', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
'foo/bar',
|
||||
|
@ -89,7 +89,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('version tag should not be too long', async () => {
|
||||
it('version tag should not be too long', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
'a'.repeat(255),
|
||||
|
@ -102,7 +102,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('version tag should not be a dot or two dots', async () => {
|
||||
it('version tag should not be a dot or two dots', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
'..',
|
||||
|
@ -125,7 +125,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('version tag should be a valid pathname', async () => {
|
||||
it('version tag should be a valid pathname', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
'<foo|bar>',
|
||||
|
@ -158,7 +158,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('version tag already exist', async () => {
|
||||
it('version tag already exist', async () => {
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
'1.0.0',
|
||||
|
@ -171,7 +171,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('no docs file to version', async () => {
|
||||
it('no docs file to version', async () => {
|
||||
const emptySiteDir = path.join(fixtureDir, 'empty-site');
|
||||
await expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -185,8 +185,8 @@ describe('docsVersion', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
it('first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation(() => {});
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
|
@ -200,7 +200,7 @@ describe('docsVersion', () => {
|
|||
versionsPath = filepath;
|
||||
versions = JSON.parse(content as string);
|
||||
});
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation();
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
const options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
sidebarPath: path.join(simpleSiteDir, 'sidebars.json'),
|
||||
|
@ -240,8 +240,8 @@ describe('docsVersion', () => {
|
|||
consoleMock.mockRestore();
|
||||
});
|
||||
|
||||
test('not the first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
it('not the first time versioning', async () => {
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation(() => {});
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
|
@ -255,7 +255,7 @@ describe('docsVersion', () => {
|
|||
versionsPath = filepath;
|
||||
versions = JSON.parse(content as string);
|
||||
});
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation();
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
const options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
sidebarPath: path.join(versionedSiteDir, 'sidebars.json'),
|
||||
|
@ -295,10 +295,10 @@ describe('docsVersion', () => {
|
|||
consoleMock.mockRestore();
|
||||
});
|
||||
|
||||
test('second docs instance versioning', async () => {
|
||||
it('second docs instance versioning', async () => {
|
||||
const pluginId = 'community';
|
||||
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation();
|
||||
const copyMock = jest.spyOn(fs, 'copy').mockImplementation(() => {});
|
||||
const writeMock = jest.spyOn(fs, 'outputFile');
|
||||
let versionedSidebar;
|
||||
let versionedSidebarPath;
|
||||
|
@ -312,7 +312,7 @@ describe('docsVersion', () => {
|
|||
versionsPath = filepath;
|
||||
versions = JSON.parse(content as string);
|
||||
});
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation();
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
const options = {
|
||||
...DEFAULT_OPTIONS,
|
||||
path: 'community',
|
||||
|
|
|
@ -21,12 +21,14 @@ function testField(params: {
|
|||
ErrorMessage: string,
|
||||
][];
|
||||
}) {
|
||||
// eslint-disable-next-line jest/require-top-level-describe
|
||||
test(`[${params.prefix}] accept valid values`, () => {
|
||||
params.validFrontMatters.forEach((frontMatter) => {
|
||||
expect(validateDocFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
});
|
||||
|
||||
// eslint-disable-next-line jest/require-top-level-describe
|
||||
test(`[${params.prefix}] convert valid values`, () => {
|
||||
params.convertibleFrontMatter?.forEach(
|
||||
([convertibleFrontMatter, convertedFrontMatter]) => {
|
||||
|
@ -37,6 +39,7 @@ function testField(params: {
|
|||
);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line jest/require-top-level-describe
|
||||
test(`[${params.prefix}] throw error for values`, () => {
|
||||
params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
|
||||
try {
|
||||
|
@ -59,13 +62,13 @@ function testField(params: {
|
|||
});
|
||||
}
|
||||
|
||||
describe('validateDocFrontMatter', () => {
|
||||
test('accept empty object', () => {
|
||||
describe('doc front matter schema', () => {
|
||||
it('accepts empty object', () => {
|
||||
const frontMatter: DocFrontMatter = {};
|
||||
expect(validateDocFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
||||
test('accept unknown field', () => {
|
||||
it('accepts unknown field', () => {
|
||||
const frontMatter = {abc: '1'};
|
||||
expect(validateDocFrontMatter(frontMatter)).toEqual(frontMatter);
|
||||
});
|
||||
|
@ -277,7 +280,7 @@ describe('validateDocFrontMatter tags', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('validateDocFrontMatter toc_min_heading_level', () => {
|
||||
describe('toc_min_heading_level', () => {
|
||||
testField({
|
||||
prefix: 'toc_min_heading_level',
|
||||
validFrontMatters: [
|
||||
|
@ -313,7 +316,7 @@ describe('validateDocFrontMatter toc_min_heading_level', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('validateDocFrontMatter toc_max_heading_level', () => {
|
||||
describe('toc_max_heading_level', () => {
|
||||
testField({
|
||||
prefix: 'toc_max_heading_level',
|
||||
validFrontMatters: [
|
||||
|
@ -349,7 +352,7 @@ describe('validateDocFrontMatter toc_max_heading_level', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('validateDocFrontMatter toc min/max consistency', () => {
|
||||
describe('toc min/max consistency', () => {
|
||||
testField({
|
||||
prefix: 'toc min/max',
|
||||
validFrontMatters: [
|
||||
|
|
|
@ -195,7 +195,7 @@ describe('simple site', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test('readVersionDocs', async () => {
|
||||
it('readVersionDocs', async () => {
|
||||
const {options, currentVersion} = await loadSite();
|
||||
const docs = await readVersionDocs(currentVersion, options);
|
||||
expect(docs.map((doc) => doc.source).sort()).toEqual(
|
||||
|
@ -219,7 +219,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('normal docs', async () => {
|
||||
it('normal docs', async () => {
|
||||
const {defaultTestUtils} = await loadSite();
|
||||
await defaultTestUtils.testMeta(path.join('foo', 'bar.md'), {
|
||||
version: 'current',
|
||||
|
@ -268,7 +268,7 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('docs with editUrl', async () => {
|
||||
it('docs with editUrl', async () => {
|
||||
const {siteDir, context, options, currentVersion} = await loadSite({
|
||||
options: {
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
||||
|
@ -317,7 +317,7 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('docs with custom editUrl & unrelated frontMatter', async () => {
|
||||
it('docs with custom editUrl & unrelated frontMatter', async () => {
|
||||
const {defaultTestUtils} = await loadSite();
|
||||
|
||||
await defaultTestUtils.testMeta('lorem.md', {
|
||||
|
@ -338,7 +338,7 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('docs with function editUrl', async () => {
|
||||
it('docs with function editUrl', async () => {
|
||||
const hardcodedEditUrl = 'hardcoded-edit-url';
|
||||
|
||||
const editUrlFunction: EditUrlFunction = jest.fn(() => hardcodedEditUrl);
|
||||
|
@ -399,7 +399,7 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('docs with last update time and author', async () => {
|
||||
it('docs with last update time and author', async () => {
|
||||
const {siteDir, context, options, currentVersion} = await loadSite({
|
||||
options: {
|
||||
showLastUpdateAuthor: true,
|
||||
|
@ -435,7 +435,7 @@ describe('simple site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('docs with slugs', async () => {
|
||||
it('docs with slugs', async () => {
|
||||
const {defaultTestUtils} = await loadSite();
|
||||
|
||||
await defaultTestUtils.testSlug(
|
||||
|
@ -473,7 +473,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('docs with invalid id', async () => {
|
||||
it('docs with invalid id', async () => {
|
||||
const {defaultTestUtils} = await loadSite();
|
||||
await expect(async () =>
|
||||
defaultTestUtils.processDocFile(
|
||||
|
@ -489,7 +489,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('custom pagination', async () => {
|
||||
it('custom pagination', async () => {
|
||||
const {defaultTestUtils, options, versionsMetadata} = await loadSite();
|
||||
const docs = await readVersionDocs(versionsMetadata[0], options);
|
||||
await expect(
|
||||
|
@ -497,7 +497,7 @@ describe('simple site', () => {
|
|||
).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('bad pagination', async () => {
|
||||
it('bad pagination', async () => {
|
||||
const {defaultTestUtils, options, versionsMetadata} = await loadSite();
|
||||
const docs = await readVersionDocs(versionsMetadata[0], options);
|
||||
docs.push(
|
||||
|
@ -577,7 +577,7 @@ describe('versioned site', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test('next docs', async () => {
|
||||
it('next docs', async () => {
|
||||
const {currentVersionTestUtils} = await loadSite();
|
||||
|
||||
await currentVersionTestUtils.testMeta(path.join('foo', 'bar.md'), {
|
||||
|
@ -631,7 +631,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('versioned docs', async () => {
|
||||
it('versioned docs', async () => {
|
||||
const {version101TestUtils, version100TestUtils} = await loadSite();
|
||||
|
||||
await version100TestUtils.testMeta(path.join('foo', 'bar.md'), {
|
||||
|
@ -690,7 +690,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('next doc slugs', async () => {
|
||||
it('next doc slugs', async () => {
|
||||
const {currentVersionTestUtils} = await loadSite();
|
||||
|
||||
await currentVersionTestUtils.testSlug(
|
||||
|
@ -711,7 +711,7 @@ describe('versioned site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('versioned doc slugs', async () => {
|
||||
it('versioned doc slugs', async () => {
|
||||
const {versionWithSlugsTestUtils} = await loadSite();
|
||||
|
||||
await versionWithSlugsTestUtils.testSlug(
|
||||
|
@ -749,7 +749,7 @@ describe('versioned site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('doc with editUrl function', async () => {
|
||||
it('doc with editUrl function', async () => {
|
||||
const hardcodedEditUrl = 'hardcoded-edit-url';
|
||||
|
||||
const editUrlFunction: EditUrlFunction = jest.fn(() => hardcodedEditUrl);
|
||||
|
@ -795,7 +795,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('translated doc with editUrl', async () => {
|
||||
it('translated doc with editUrl', async () => {
|
||||
const {siteDir, context, options, version100} = await loadSite({
|
||||
options: {
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
||||
|
@ -830,7 +830,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('translated en doc with editUrl and editCurrentVersion=true', async () => {
|
||||
it('translated en doc with editUrl and editCurrentVersion=true', async () => {
|
||||
const {siteDir, context, options, version100} = await loadSite({
|
||||
options: {
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
||||
|
@ -865,7 +865,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('translated fr doc with editUrl and editLocalizedFiles=true', async () => {
|
||||
it('translated fr doc with editUrl and editLocalizedFiles=true', async () => {
|
||||
const {siteDir, context, options, version100} = await loadSite({
|
||||
options: {
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
||||
|
@ -901,7 +901,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('translated fr doc with editUrl and editLocalizedFiles=true + editCurrentVersion=true', async () => {
|
||||
it('translated fr doc with editUrl and editLocalizedFiles=true + editCurrentVersion=true', async () => {
|
||||
const {siteDir, context, options, version100} = await loadSite({
|
||||
options: {
|
||||
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
||||
|
@ -940,7 +940,7 @@ describe('versioned site', () => {
|
|||
});
|
||||
|
||||
describe('isConventionalDocIndex', () => {
|
||||
test('supports readme', () => {
|
||||
it('supports readme', () => {
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'readme',
|
||||
|
@ -971,7 +971,7 @@ describe('isConventionalDocIndex', () => {
|
|||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('supports index', () => {
|
||||
it('supports index', () => {
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'index',
|
||||
|
@ -1002,7 +1002,7 @@ describe('isConventionalDocIndex', () => {
|
|||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('supports <categoryName>/<categoryName>.md', () => {
|
||||
it('supports <categoryName>/<categoryName>.md', () => {
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'someCategory',
|
||||
|
@ -1040,7 +1040,7 @@ describe('isConventionalDocIndex', () => {
|
|||
).toEqual(true);
|
||||
});
|
||||
|
||||
test('reject other cases', () => {
|
||||
it('reject other cases', () => {
|
||||
expect(
|
||||
isCategoryIndex({
|
||||
fileName: 'some_Category',
|
||||
|
|
|
@ -113,7 +113,7 @@ Entries created:
|
|||
};
|
||||
|
||||
describe('sidebar', () => {
|
||||
test('site with wrong sidebar content', async () => {
|
||||
it('site with wrong sidebar content', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const context = await loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'wrong-sidebars.json');
|
||||
|
@ -123,10 +123,32 @@ describe('sidebar', () => {
|
|||
sidebarPath,
|
||||
}),
|
||||
);
|
||||
await expect(plugin.loadContent!()).rejects.toThrowErrorMatchingSnapshot();
|
||||
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"
|
||||
`);
|
||||
});
|
||||
|
||||
test('site with wrong sidebar file path', async () => {
|
||||
it('site with wrong sidebar file path', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
|
||||
const context = await loadContext(siteDir);
|
||||
|
||||
|
@ -147,7 +169,7 @@ describe('sidebar', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('site with undefined sidebar', async () => {
|
||||
it('site with undefined sidebar', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
|
||||
const context = await loadContext(siteDir);
|
||||
const plugin = await pluginContentDocs(
|
||||
|
@ -159,24 +181,10 @@ describe('sidebar', () => {
|
|||
const result = await plugin.loadContent!();
|
||||
|
||||
expect(result.loadedVersions).toHaveLength(1);
|
||||
expect(result.loadedVersions[0].sidebars).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"defaultSidebar": Array [
|
||||
Object {
|
||||
"id": "hello-1",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "hello-2",
|
||||
"label": "Hello 2 From Doc",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
expect(result.loadedVersions[0].sidebars).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('site with disabled sidebar', async () => {
|
||||
it('site with disabled sidebar', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'site-with-doc-label');
|
||||
const context = await loadContext(siteDir);
|
||||
const plugin = await pluginContentDocs(
|
||||
|
@ -195,7 +203,7 @@ describe('sidebar', () => {
|
|||
describe('empty/no docs website', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'empty-site');
|
||||
|
||||
test('no files in docs folder', async () => {
|
||||
it('no files in docs folder', async () => {
|
||||
const context = await loadContext(siteDir);
|
||||
await fs.ensureDir(path.join(siteDir, 'docs'));
|
||||
const plugin = await pluginContentDocs(
|
||||
|
@ -209,7 +217,7 @@ describe('empty/no docs website', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('docs folder does not exist', async () => {
|
||||
it('docs folder does not exist', async () => {
|
||||
const context = await loadContext(siteDir);
|
||||
await expect(
|
||||
pluginContentDocs(
|
||||
|
@ -245,11 +253,11 @@ describe('simple website', () => {
|
|||
return {siteDir, context, sidebarPath, plugin, pluginContentDir};
|
||||
}
|
||||
|
||||
test('extendCli - docsVersion', async () => {
|
||||
it('extendCli - docsVersion', async () => {
|
||||
const {siteDir, sidebarPath, plugin} = await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
.mockImplementation(async () => {});
|
||||
const cli = new commander.Command();
|
||||
// @ts-expect-error: in actual usage, we pass the static commander instead
|
||||
// of the new command
|
||||
|
@ -265,22 +273,14 @@ describe('simple website', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', async () => {
|
||||
it('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
"docs/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`);
|
||||
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);
|
||||
|
@ -294,7 +294,7 @@ describe('simple website', () => {
|
|||
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
|
||||
});
|
||||
|
||||
test('configureWebpack', async () => {
|
||||
it('configureWebpack', async () => {
|
||||
const {plugin} = await loadSite();
|
||||
|
||||
const content = await plugin.loadContent?.();
|
||||
|
@ -316,7 +316,7 @@ describe('simple website', () => {
|
|||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
test('content', async () => {
|
||||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(1);
|
||||
|
@ -370,11 +370,11 @@ describe('versioned website', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test('extendCli - docsVersion', async () => {
|
||||
it('extendCli - docsVersion', async () => {
|
||||
const {siteDir, routeBasePath, sidebarPath, plugin} = await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
.mockImplementation(async () => {});
|
||||
const cli = new commander.Command();
|
||||
// @ts-expect-error: in actual usage, we pass the static commander instead
|
||||
// of the new command
|
||||
|
@ -390,33 +390,14 @@ describe('versioned website', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', async () => {
|
||||
it('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
"docs/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-1.0.1-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.1/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.0/**/_category_.{json,yml,yaml}",
|
||||
"versioned_sidebars/version-withSlugs-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-withSlugs/**/*.{md,mdx}",
|
||||
"versioned_docs/version-withSlugs/**/*.{md,mdx}",
|
||||
"versioned_docs/version-withSlugs/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`);
|
||||
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);
|
||||
|
@ -449,7 +430,7 @@ describe('versioned website', () => {
|
|||
expect(isMatch('super/docs/hello.md', matchPattern)).toEqual(false);
|
||||
});
|
||||
|
||||
test('content', async () => {
|
||||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(4);
|
||||
|
@ -519,12 +500,12 @@ describe('versioned website (community)', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test('extendCli - docsVersion', async () => {
|
||||
it('extendCli - docsVersion', async () => {
|
||||
const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
|
||||
await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
.mockImplementation(async () => {});
|
||||
const cli = new commander.Command();
|
||||
// @ts-expect-error: in actual usage, we pass the static commander instead
|
||||
// of the new command
|
||||
|
@ -540,25 +521,14 @@ describe('versioned website (community)', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', async () => {
|
||||
it('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"community_sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/current/**/*.{md,mdx}",
|
||||
"community/**/*.{md,mdx}",
|
||||
"community/**/_category_.{json,yml,yaml}",
|
||||
"community_versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/version-1.0.0/**/*.{md,mdx}",
|
||||
"community_versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"community_versioned_docs/version-1.0.0/**/_category_.{json,yml,yaml}",
|
||||
]
|
||||
`);
|
||||
expect(matchPattern).toMatchSnapshot();
|
||||
expect(isMatch('community/team.md', matchPattern)).toEqual(true);
|
||||
expect(
|
||||
isMatch('community_versioned_docs/version-1.0.0/team.md', matchPattern),
|
||||
|
@ -581,7 +551,7 @@ describe('versioned website (community)', () => {
|
|||
).toEqual(false);
|
||||
});
|
||||
|
||||
test('content', async () => {
|
||||
it('content', async () => {
|
||||
const {plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(2);
|
||||
|
@ -625,20 +595,20 @@ describe('site with doc label', () => {
|
|||
return {content};
|
||||
}
|
||||
|
||||
test('label in sidebar.json is used', async () => {
|
||||
it('label in sidebar.json is used', async () => {
|
||||
const {content} = await loadSite();
|
||||
const loadedVersion = content.loadedVersions[0];
|
||||
const sidebarProps = toSidebarsProp(loadedVersion);
|
||||
|
||||
expect(sidebarProps.docs[0].label).toBe('Hello One');
|
||||
expect(sidebarProps.docs[0].label).toEqual('Hello One');
|
||||
});
|
||||
|
||||
test('sidebar_label in doc has higher precedence over label in sidebar.json', async () => {
|
||||
it('sidebar_label in doc has higher precedence over label in sidebar.json', async () => {
|
||||
const {content} = await loadSite();
|
||||
const loadedVersion = content.loadedVersions[0];
|
||||
const sidebarProps = toSidebarsProp(loadedVersion);
|
||||
|
||||
expect(sidebarProps.docs[1].label).toBe('Hello 2 From Doc');
|
||||
expect(sidebarProps.docs[1].label).toEqual('Hello 2 From Doc');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -662,14 +632,14 @@ describe('site with full autogenerated sidebar', () => {
|
|||
return {content, siteDir};
|
||||
}
|
||||
|
||||
test('sidebar is fully autogenerated', async () => {
|
||||
it('sidebar is fully autogenerated', async () => {
|
||||
const {content} = await loadSite();
|
||||
const version = content.loadedVersions[0];
|
||||
|
||||
expect(version.sidebars).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('docs in fully generated sidebar have correct metadata', async () => {
|
||||
it('docs in fully generated sidebar have correct metadata', async () => {
|
||||
const {content} = await loadSite();
|
||||
const version = content.loadedVersions[0];
|
||||
|
||||
|
@ -720,14 +690,14 @@ describe('site with partial autogenerated sidebars', () => {
|
|||
return {content, siteDir};
|
||||
}
|
||||
|
||||
test('sidebar is partially autogenerated', async () => {
|
||||
it('sidebar is partially autogenerated', async () => {
|
||||
const {content} = await loadSite();
|
||||
const version = content.loadedVersions[0];
|
||||
|
||||
expect(version.sidebars).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('docs in partially generated sidebar have correct metadata', async () => {
|
||||
it('docs in partially generated sidebar have correct metadata', async () => {
|
||||
const {content} = await loadSite();
|
||||
const version = content.loadedVersions[0];
|
||||
|
||||
|
@ -773,7 +743,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
|
|||
return {content, siteDir};
|
||||
}
|
||||
|
||||
test('sidebar is partially autogenerated', async () => {
|
||||
it('sidebar is partially autogenerated', async () => {
|
||||
const {content} = await loadSite();
|
||||
const version = content.loadedVersions[0];
|
||||
|
||||
|
@ -800,7 +770,7 @@ describe('site with custom sidebar items generator', () => {
|
|||
return {content, siteDir};
|
||||
}
|
||||
|
||||
test('sidebarItemsGenerator is called with appropriate data', async () => {
|
||||
it('sidebarItemsGenerator is called with appropriate data', async () => {
|
||||
const customSidebarItemsGeneratorMock = jest.fn(
|
||||
async (_arg: SidebarItemsGeneratorOptionArgs) => [],
|
||||
);
|
||||
|
@ -830,7 +800,7 @@ describe('site with custom sidebar items generator', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
|
||||
it('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
|
||||
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
|
||||
async () => [
|
||||
{type: 'doc', id: 'API/api-overview'},
|
||||
|
@ -843,7 +813,7 @@ describe('site with custom sidebar items generator', () => {
|
|||
expect(version.sidebars).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('sidebarItemsGenerator can wrap/enhance/sort/reverse the default sidebar generator', async () => {
|
||||
it('sidebarItemsGenerator can wrap/enhance/sort/reverse the default sidebar generator', async () => {
|
||||
function reverseSidebarItems(items: SidebarItem[]): SidebarItem[] {
|
||||
const result: SidebarItem[] = items.map((item) => {
|
||||
if (item.type === 'category') {
|
||||
|
|
|
@ -12,12 +12,12 @@ import shell from 'shelljs';
|
|||
|
||||
import {getFileLastUpdate} from '../lastUpdate';
|
||||
|
||||
describe('lastUpdate', () => {
|
||||
describe('getFileLastUpdate', () => {
|
||||
const existingFilePath = path.join(
|
||||
__dirname,
|
||||
'__fixtures__/simple-site/docs/hello.md',
|
||||
);
|
||||
test('existing test file in repository with Git timestamp', async () => {
|
||||
it('existing test file in repository with Git timestamp', async () => {
|
||||
const lastUpdateData = await getFileLastUpdate(existingFilePath);
|
||||
expect(lastUpdateData).not.toBeNull();
|
||||
|
||||
|
@ -29,7 +29,7 @@ describe('lastUpdate', () => {
|
|||
expect(typeof timestamp).toBe('number');
|
||||
});
|
||||
|
||||
test('existing test file with spaces in path', async () => {
|
||||
it('existing test file with spaces in path', async () => {
|
||||
const filePathWithSpace = path.join(
|
||||
__dirname,
|
||||
'__fixtures__/simple-site/docs/doc with space.md',
|
||||
|
@ -45,8 +45,10 @@ describe('lastUpdate', () => {
|
|||
expect(typeof timestamp).toBe('number');
|
||||
});
|
||||
|
||||
test('non-existing file', async () => {
|
||||
const consoleMock = jest.spyOn(console, 'error').mockImplementation();
|
||||
it('non-existing file', async () => {
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
const nonExistingFileName = '.nonExisting';
|
||||
const nonExistingFilePath = path.join(
|
||||
__dirname,
|
||||
|
@ -63,16 +65,18 @@ describe('lastUpdate', () => {
|
|||
consoleMock.mockRestore();
|
||||
});
|
||||
|
||||
test('temporary created file that has no git timestamp', async () => {
|
||||
it('temporary created file that has no git timestamp', async () => {
|
||||
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
|
||||
await fs.writeFile(tempFilePath, 'Lorem ipsum :)');
|
||||
await expect(getFileLastUpdate(tempFilePath)).resolves.toBeNull();
|
||||
await fs.unlink(tempFilePath);
|
||||
});
|
||||
|
||||
test('Git does not exist', async () => {
|
||||
it('git does not exist', async () => {
|
||||
const mock = jest.spyOn(shell, 'which').mockImplementationOnce(() => null);
|
||||
const consoleMock = jest.spyOn(console, 'warn').mockImplementation();
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'warn')
|
||||
.mockImplementation(() => {});
|
||||
const lastUpdateData = await getFileLastUpdate(existingFilePath);
|
||||
expect(lastUpdateData).toBeNull();
|
||||
expect(consoleMock).toHaveBeenLastCalledWith(
|
||||
|
|
|
@ -69,7 +69,7 @@ describe('stripNumberPrefix', () => {
|
|||
return stripNumberPrefix(str, DefaultNumberPrefixParser);
|
||||
}
|
||||
|
||||
test('should strip number prefix if present', () => {
|
||||
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');
|
||||
|
@ -111,7 +111,7 @@ describe('stripNumberPrefix', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should not strip number prefix if pattern does not match', () => {
|
||||
it('does not strip number prefix if pattern does not match', () => {
|
||||
IgnoredNumberPrefixPatterns.forEach((badPattern) => {
|
||||
expect(stripNumberPrefixDefault(badPattern)).toEqual(badPattern);
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ describe('stripNumberPrefix', () => {
|
|||
});
|
||||
|
||||
describe('stripPathNumberPrefix', () => {
|
||||
test('should strip number prefixes in paths', () => {
|
||||
it('strips number prefixes in paths', () => {
|
||||
expect(
|
||||
stripPathNumberPrefixes(
|
||||
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
||||
|
@ -128,7 +128,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
).toEqual('MyRootFolder0/MySubFolder1/MyDeepFolder2/MyDoc3');
|
||||
});
|
||||
|
||||
test('should strip number prefixes in paths with custom parser', () => {
|
||||
it('strips number prefixes in paths with custom parser', () => {
|
||||
function stripPathNumberPrefixCustom(str: string) {
|
||||
return {
|
||||
filename: str.substring(1, str.length),
|
||||
|
@ -141,7 +141,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
).toEqual('aaa/bbb/ccc');
|
||||
});
|
||||
|
||||
test('should strip number prefixes in paths with disabled parser', () => {
|
||||
it('does not strip number prefixes in paths with disabled parser', () => {
|
||||
expect(
|
||||
stripPathNumberPrefixes(
|
||||
'0-MyRootFolder0/1 - MySubFolder1/2. MyDeepFolder2/3 _MyDoc3',
|
||||
|
@ -152,7 +152,7 @@ describe('stripPathNumberPrefix', () => {
|
|||
});
|
||||
|
||||
describe('DefaultNumberPrefixParser', () => {
|
||||
test('should extract number prefix if present', () => {
|
||||
it('extracts number prefix if present', () => {
|
||||
expect(DefaultNumberPrefixParser('0-My Doc')).toEqual({
|
||||
filename: 'My Doc',
|
||||
numberPrefix: 0,
|
||||
|
@ -188,7 +188,7 @@ describe('DefaultNumberPrefixParser', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should not extract number prefix if pattern does not match', () => {
|
||||
it('does not extract number prefix if pattern does not match', () => {
|
||||
IgnoredNumberPrefixPatterns.forEach((badPattern) => {
|
||||
expect(DefaultNumberPrefixParser(badPattern)).toEqual({
|
||||
filename: badPattern,
|
||||
|
|
|
@ -30,13 +30,13 @@ function testValidateOptions(options: Partial<PluginOptions>) {
|
|||
}
|
||||
|
||||
describe('normalizeDocsPluginOptions', () => {
|
||||
test('should return default options for undefined user options', async () => {
|
||||
it('returns default options for undefined user options', async () => {
|
||||
const {value, error} = await OptionsSchema.validate({});
|
||||
expect(value).toEqual(DEFAULT_OPTIONS);
|
||||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept correctly defined user options', async () => {
|
||||
it('accepts correctly defined user options', async () => {
|
||||
const userOptions = {
|
||||
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
||||
routeBasePath: 'my-docs', // URL Route.
|
||||
|
@ -82,7 +82,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept correctly defined remark and rehype plugin options', async () => {
|
||||
it('accepts correctly defined remark and rehype plugin options', async () => {
|
||||
const userOptions = {
|
||||
...DEFAULT_OPTIONS,
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
|
@ -98,7 +98,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept admonitions false', async () => {
|
||||
it('accepts admonitions false', async () => {
|
||||
const admonitionsFalse = {
|
||||
...DEFAULT_OPTIONS,
|
||||
admonitions: false,
|
||||
|
@ -108,7 +108,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser function', () => {
|
||||
it('accepts numberPrefixParser function', () => {
|
||||
function customNumberPrefixParser() {}
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
|
@ -122,7 +122,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser false', () => {
|
||||
it('accepts numberPrefixParser false', () => {
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
...DEFAULT_OPTIONS,
|
||||
|
@ -135,7 +135,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser true', () => {
|
||||
it('accepts numberPrefixParser true', () => {
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
...DEFAULT_OPTIONS,
|
||||
|
@ -148,7 +148,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should reject admonitions true', async () => {
|
||||
it('rejects admonitions true', async () => {
|
||||
const admonitionsTrue = {
|
||||
...DEFAULT_OPTIONS,
|
||||
admonitions: true,
|
||||
|
@ -159,7 +159,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject invalid remark plugin options', () => {
|
||||
it('rejects invalid remark plugin options', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
remarkPlugins: [[{option1: '42'}, markdownPluginsFunctionStub]],
|
||||
|
@ -169,7 +169,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject invalid rehype plugin options', () => {
|
||||
it('rejects invalid rehype plugin options', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
rehypePlugins: [
|
||||
|
@ -185,7 +185,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject bad path inputs', () => {
|
||||
it('rejects bad path inputs', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
path: 2,
|
||||
|
@ -193,7 +193,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
}).toThrowErrorMatchingInlineSnapshot(`"\\"path\\" must be a string"`);
|
||||
});
|
||||
|
||||
test('should reject bad include inputs', () => {
|
||||
it('rejects bad include inputs', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
include: '**/*.{md,mdx}',
|
||||
|
@ -201,7 +201,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
}).toThrowErrorMatchingInlineSnapshot(`"\\"include\\" must be an array"`);
|
||||
});
|
||||
|
||||
test('should reject bad showLastUpdateTime inputs', () => {
|
||||
it('rejects bad showLastUpdateTime inputs', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
showLastUpdateTime: 'true',
|
||||
|
@ -211,7 +211,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject bad remarkPlugins input', () => {
|
||||
it('rejects bad remarkPlugins input', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
remarkPlugins: 'remark-math',
|
||||
|
@ -221,7 +221,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject bad lastVersion', () => {
|
||||
it('rejects bad lastVersion', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
lastVersion: false,
|
||||
|
@ -231,7 +231,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should reject bad versions', () => {
|
||||
it('rejects bad versions', () => {
|
||||
expect(() => {
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
versions: {
|
||||
|
@ -249,7 +249,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('should handle sidebarCollapsed option inconsistencies', () => {
|
||||
it('handles sidebarCollapsed option inconsistencies', () => {
|
||||
expect(
|
||||
testValidateOptions({
|
||||
...DEFAULT_OPTIONS,
|
||||
|
|
|
@ -14,7 +14,7 @@ describe('toTagDocListProp', () => {
|
|||
|
||||
const allTagsPath = '/all/tags';
|
||||
|
||||
test('should work', () => {
|
||||
it('works', () => {
|
||||
const tag: Tag = {
|
||||
name: 'tag1',
|
||||
permalink: '/tag1',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import getSlug from '../slug';
|
||||
|
||||
describe('getSlug', () => {
|
||||
test('should default to dirname/id', () => {
|
||||
it('defaults to dirname/id', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
|
@ -25,7 +25,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/dir/subdir/doc');
|
||||
});
|
||||
|
||||
test('should handle conventional doc indexes', () => {
|
||||
it('handles conventional doc indexes', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
|
@ -70,7 +70,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/dir/subdir/');
|
||||
});
|
||||
|
||||
test('should ignore conventional doc index when explicit slug front matter is provided', () => {
|
||||
it('ignores conventional doc index when explicit slug front matter is provided', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
|
@ -81,7 +81,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/my/frontMatterSlug');
|
||||
});
|
||||
|
||||
test('can strip dir number prefixes', () => {
|
||||
it('can strip dir number prefixes', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'doc',
|
||||
|
@ -101,7 +101,7 @@ describe('getSlug', () => {
|
|||
});
|
||||
|
||||
// See https://github.com/facebook/docusaurus/issues/3223
|
||||
test('should handle special chars in doc path', () => {
|
||||
it('handles special chars in doc path', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'my dôc',
|
||||
|
@ -111,7 +111,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/dir with spâce/hey $hello/my dôc');
|
||||
});
|
||||
|
||||
test('should handle current dir', () => {
|
||||
it('handles current dir', () => {
|
||||
expect(
|
||||
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '.'}),
|
||||
).toEqual('/doc');
|
||||
|
@ -120,7 +120,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/doc');
|
||||
});
|
||||
|
||||
test('should resolve absolute slug front matter', () => {
|
||||
it('resolves absolute slug front matter', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
@ -147,7 +147,7 @@ describe('getSlug', () => {
|
|||
).toEqual('/abc/def');
|
||||
});
|
||||
|
||||
test('should resolve relative slug front matter', () => {
|
||||
it('resolves relative slug front matter', () => {
|
||||
expect(
|
||||
getSlug({
|
||||
baseID: 'any',
|
||||
|
|
|
@ -142,20 +142,20 @@ function getSampleTranslationFilesTranslated() {
|
|||
}
|
||||
|
||||
describe('getLoadedContentTranslationFiles', () => {
|
||||
test('should return translation files matching snapshot', async () => {
|
||||
it('returns translation files', async () => {
|
||||
expect(getSampleTranslationFiles()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe('translateLoadedContent', () => {
|
||||
test('should not translate anything if translation files are untranslated', () => {
|
||||
it('does not translate anything if translation files are untranslated', () => {
|
||||
const translationFiles = getSampleTranslationFiles();
|
||||
expect(
|
||||
translateLoadedContent(SampleLoadedContent, translationFiles),
|
||||
).toEqual(SampleLoadedContent);
|
||||
});
|
||||
|
||||
test('should return translated loaded content matching snapshot', () => {
|
||||
it('returns translated loaded content', () => {
|
||||
const translationFiles = getSampleTranslationFilesTranslated();
|
||||
expect(
|
||||
translateLoadedContent(SampleLoadedContent, translationFiles),
|
||||
|
|
|
@ -27,7 +27,7 @@ const DefaultI18N: I18n = {
|
|||
};
|
||||
|
||||
describe('version paths', () => {
|
||||
test('getVersionsFilePath', () => {
|
||||
it('getVersionsFilePath', () => {
|
||||
expect(getVersionsFilePath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
`someSiteDir${path.sep}versions.json`,
|
||||
);
|
||||
|
@ -36,7 +36,7 @@ describe('version paths', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getVersionedDocsDirPath', () => {
|
||||
it('getVersionedDocsDirPath', () => {
|
||||
expect(getVersionedDocsDirPath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
`someSiteDir${path.sep}versioned_docs`,
|
||||
);
|
||||
|
@ -45,7 +45,7 @@ describe('version paths', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getVersionedSidebarsDirPath', () => {
|
||||
it('getVersionedSidebarsDirPath', () => {
|
||||
expect(getVersionedSidebarsDirPath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
`someSiteDir${path.sep}versioned_sidebars`,
|
||||
);
|
||||
|
@ -90,7 +90,7 @@ describe('simple site', () => {
|
|||
return {simpleSiteDir, defaultOptions, defaultContext, vCurrent};
|
||||
}
|
||||
|
||||
test('readVersionsMetadata simple site', async () => {
|
||||
it('readVersionsMetadata simple site', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -101,7 +101,7 @@ describe('simple site', () => {
|
|||
expect(versionsMetadata).toEqual([vCurrent]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with base url', async () => {
|
||||
it('readVersionsMetadata simple site with base url', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -121,7 +121,7 @@ describe('simple site', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with current version config', async () => {
|
||||
it('readVersionsMetadata simple site with current version config', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -154,7 +154,7 @@ describe('simple site', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with unknown lastVersion should throw', async () => {
|
||||
it('readVersionsMetadata simple site with unknown lastVersion should throw', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -167,7 +167,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with unknown version configurations should throw', async () => {
|
||||
it('readVersionsMetadata simple site with unknown version configurations should throw', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -187,7 +187,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site with disableVersioning while single version should throw', async () => {
|
||||
it('readVersionsMetadata simple site with disableVersioning while single version should throw', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -200,7 +200,7 @@ describe('simple site', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata simple site without including current version should throw', async () => {
|
||||
it('readVersionsMetadata simple site without including current version should throw', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -325,7 +325,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test('readVersionsMetadata versioned site', async () => {
|
||||
it('readVersionsMetadata versioned site', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
|
||||
await loadSite();
|
||||
|
||||
|
@ -337,7 +337,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
expect(versionsMetadata).toEqual([vCurrent, v101, v100, vwithSlugs]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
|
||||
it('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
|
||||
const {defaultOptions, defaultContext, v101, v100, vwithSlugs} =
|
||||
await loadSite();
|
||||
|
||||
|
@ -354,7 +354,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with version options', async () => {
|
||||
it('readVersionsMetadata versioned site with version options', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
|
||||
await loadSite();
|
||||
|
||||
|
@ -408,7 +408,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with editUrl', async () => {
|
||||
it('readVersionsMetadata versioned site with editUrl', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
|
||||
await loadSite();
|
||||
|
||||
|
@ -452,7 +452,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
|
||||
it('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
|
||||
await loadSite();
|
||||
|
||||
|
@ -497,7 +497,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with onlyIncludeVersions option', async () => {
|
||||
it('readVersionsMetadata versioned site with onlyIncludeVersions option', async () => {
|
||||
const {defaultOptions, defaultContext, v101, vwithSlugs} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -512,7 +512,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
expect(versionsMetadata).toEqual([v101, vwithSlugs]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with disableVersioning', async () => {
|
||||
it('readVersionsMetadata versioned site with disableVersioning', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -533,7 +533,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with all versions disabled', async () => {
|
||||
it('readVersionsMetadata versioned site with all versions disabled', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -550,7 +550,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with empty onlyIncludeVersions', async () => {
|
||||
it('readVersionsMetadata versioned site with empty onlyIncludeVersions', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -566,7 +566,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with unknown versions in onlyIncludeVersions', async () => {
|
||||
it('readVersionsMetadata versioned site with unknown versions in onlyIncludeVersions', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -582,7 +582,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with lastVersion not in onlyIncludeVersions', async () => {
|
||||
it('readVersionsMetadata versioned site with lastVersion not in onlyIncludeVersions', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
@ -599,7 +599,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site with invalid versions.json file', async () => {
|
||||
it('readVersionsMetadata versioned site with invalid versions.json file', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => ({
|
||||
|
@ -681,7 +681,7 @@ describe('versioned site, pluginId=community', () => {
|
|||
return {versionedSiteDir, defaultOptions, defaultContext, vCurrent, v100};
|
||||
}
|
||||
|
||||
test('readVersionsMetadata versioned site (community)', async () => {
|
||||
it('readVersionsMetadata versioned site (community)', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent, v100} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -692,7 +692,7 @@ describe('versioned site, pluginId=community', () => {
|
|||
expect(versionsMetadata).toEqual([vCurrent, v100]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site (community) with includeCurrentVersion=false', async () => {
|
||||
it('readVersionsMetadata versioned site (community) with includeCurrentVersion=false', async () => {
|
||||
const {defaultOptions, defaultContext, v100} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -706,7 +706,7 @@ describe('versioned site, pluginId=community', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site (community) with disableVersioning', async () => {
|
||||
it('readVersionsMetadata versioned site (community) with disableVersioning', async () => {
|
||||
const {defaultOptions, defaultContext, vCurrent} = await loadSite();
|
||||
|
||||
const versionsMetadata = await readVersionsMetadata({
|
||||
|
@ -727,7 +727,7 @@ describe('versioned site, pluginId=community', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('readVersionsMetadata versioned site (community) with all versions disabled', async () => {
|
||||
it('readVersionsMetadata versioned site (community) with all versions disabled', async () => {
|
||||
const {defaultOptions, defaultContext} = await loadSite();
|
||||
|
||||
await expect(
|
||||
|
|
|
@ -20,7 +20,7 @@ import type {
|
|||
import _ from 'lodash';
|
||||
|
||||
describe('docsClientUtils', () => {
|
||||
test('getActivePlugin', () => {
|
||||
it('getActivePlugin', () => {
|
||||
const data: Record<string, GlobalPluginData> = {
|
||||
pluginIosId: {
|
||||
path: '/ios',
|
||||
|
@ -91,7 +91,7 @@ describe('docsClientUtils', () => {
|
|||
).toEqual('pluginAndroidId');
|
||||
});
|
||||
|
||||
test('getLatestVersion', () => {
|
||||
it('getLatestVersion', () => {
|
||||
const versions: GlobalVersion[] = [
|
||||
{
|
||||
name: 'version1',
|
||||
|
@ -127,7 +127,7 @@ describe('docsClientUtils', () => {
|
|||
).toEqual(versions[1]);
|
||||
});
|
||||
|
||||
test('getActiveVersion', () => {
|
||||
it('getActiveVersion', () => {
|
||||
const data: GlobalPluginData = {
|
||||
path: 'docs',
|
||||
versions: [
|
||||
|
@ -175,7 +175,7 @@ describe('docsClientUtils', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getActiveDocContext', () => {
|
||||
it('getActiveDocContext', () => {
|
||||
const versionNext: GlobalVersion = {
|
||||
name: 'next',
|
||||
label: 'next',
|
||||
|
@ -304,7 +304,7 @@ describe('docsClientUtils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('getDocVersionSuggestions', () => {
|
||||
it('getDocVersionSuggestions', () => {
|
||||
const versionNext: GlobalVersion = {
|
||||
name: 'next',
|
||||
label: 'next',
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`transform nothing 1`] = `
|
||||
exports[`linkify transforms absolute links in versioned docs 1`] = `
|
||||
"### Existing Docs
|
||||
|
||||
- [doc1](/docs/1.0.0/subdir/doc1)
|
||||
|
||||
### With hash
|
||||
|
||||
- [doc2](/docs/1.0.0/doc2#existing-docs)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`linkify transforms nothing with no links 1`] = `
|
||||
"# Don't transform any link here
|
||||
|
||||

|
||||
|
@ -17,41 +28,7 @@ exports[`transform nothing 1`] = `
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`transform relative links 1`] = `
|
||||
"### Relative linking
|
||||
|
||||
- [doc1](/docs/doc2)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`transform to correct links 1`] = `
|
||||
"### Existing Docs
|
||||
|
||||
- [doc1](/docs/doc1)
|
||||
- [doc2](/docs/doc2)
|
||||
- [doc3](/docs/subdir/doc3)
|
||||
|
||||
## Repeating Docs
|
||||
|
||||
- [doc1](/docs/doc1)
|
||||
- [doc2](/docs/doc2)
|
||||
|
||||
- [doc-localized](/fr/doc-localized)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`transforms absolute links in versioned docs 1`] = `
|
||||
"### Existing Docs
|
||||
|
||||
- [doc1](/docs/1.0.0/subdir/doc1)
|
||||
|
||||
### With hash
|
||||
|
||||
- [doc2](/docs/1.0.0/doc2#existing-docs)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`transforms reference links 1`] = `
|
||||
exports[`linkify transforms reference links 1`] = `
|
||||
"### Existing Docs
|
||||
|
||||
- [doc1][doc1]
|
||||
|
@ -74,9 +51,32 @@ exports[`transforms reference links 1`] = `
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`transforms relative links in versioned docs 1`] = `
|
||||
exports[`linkify transforms relative links 1`] = `
|
||||
"### Relative linking
|
||||
|
||||
- [doc1](/docs/doc2)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`linkify transforms relative links in versioned docs 1`] = `
|
||||
"### Relative linking
|
||||
|
||||
- [doc1](/docs/1.0.0/doc2)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`linkify transforms to correct links 1`] = `
|
||||
"### Existing Docs
|
||||
|
||||
- [doc1](/docs/doc1)
|
||||
- [doc2](/docs/doc2)
|
||||
- [doc3](/docs/subdir/doc3)
|
||||
|
||||
## Repeating Docs
|
||||
|
||||
- [doc1](/docs/doc1)
|
||||
- [doc2](/docs/doc2)
|
||||
|
||||
- [doc-localized](/fr/doc-localized)
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -100,95 +100,97 @@ const transform = async (
|
|||
return [content, transformedContent];
|
||||
};
|
||||
|
||||
test('transform nothing', async () => {
|
||||
const doc1 = path.join(versionCurrent.contentPath, 'doc1.md');
|
||||
const [content, transformedContent] = await transform(doc1);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(content).toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('transform to correct links', async () => {
|
||||
const doc2 = path.join(versionCurrent.contentPath, 'doc2.md');
|
||||
const [content, transformedContent] = await transform(doc2);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/doc1');
|
||||
expect(transformedContent).toContain('](/docs/doc2');
|
||||
expect(transformedContent).toContain('](/docs/subdir/doc3');
|
||||
expect(transformedContent).toContain('](/fr/doc-localized');
|
||||
expect(transformedContent).not.toContain('](doc1.md)');
|
||||
expect(transformedContent).not.toContain('](./doc2.md)');
|
||||
expect(transformedContent).not.toContain('](subdir/doc3.md)');
|
||||
expect(transformedContent).not.toContain('](/doc-localized');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('transform relative links', async () => {
|
||||
const doc3 = path.join(versionCurrent.contentPath, 'subdir', 'doc3.md');
|
||||
|
||||
const [content, transformedContent] = await transform(doc3);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/doc2');
|
||||
expect(transformedContent).not.toContain('](../doc2.md)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('transforms reference links', async () => {
|
||||
const doc4 = path.join(versionCurrent.contentPath, 'doc4.md');
|
||||
const [content, transformedContent] = await transform(doc4);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('[doc1]: /docs/doc1');
|
||||
expect(transformedContent).toContain('[doc2]: /docs/doc2');
|
||||
expect(transformedContent).not.toContain('[doc1]: doc1.md');
|
||||
expect(transformedContent).not.toContain('[doc2]: ./doc2.md');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('report broken markdown links', async () => {
|
||||
const doc5 = path.join(versionCurrent.contentPath, 'doc5.md');
|
||||
const onBrokenMarkdownLink = jest.fn();
|
||||
const [content, transformedContent] = await transform(doc5, {
|
||||
onBrokenMarkdownLink,
|
||||
describe('linkify', () => {
|
||||
it('transforms nothing with no links', async () => {
|
||||
const doc1 = path.join(versionCurrent.contentPath, 'doc1.md');
|
||||
const [content, transformedContent] = await transform(doc1);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(content).toEqual(transformedContent);
|
||||
});
|
||||
expect(transformedContent).toEqual(content);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenCalledTimes(4);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(1, {
|
||||
filePath: doc5,
|
||||
link: 'docNotExist1.md',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(2, {
|
||||
filePath: doc5,
|
||||
link: './docNotExist2.mdx',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(3, {
|
||||
filePath: doc5,
|
||||
link: '../docNotExist3.mdx',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(4, {
|
||||
filePath: doc5,
|
||||
link: './subdir/docNotExist4.md',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
});
|
||||
|
||||
test('transforms absolute links in versioned docs', async () => {
|
||||
const doc2 = path.join(version100.contentPath, 'doc2.md');
|
||||
const [content, transformedContent] = await transform(doc2);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/subdir/doc1');
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/doc2#existing-docs');
|
||||
expect(transformedContent).not.toContain('](subdir/doc1.md)');
|
||||
expect(transformedContent).not.toContain('](doc2.md#existing-docs)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
it('transforms to correct links', async () => {
|
||||
const doc2 = path.join(versionCurrent.contentPath, 'doc2.md');
|
||||
const [content, transformedContent] = await transform(doc2);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/doc1');
|
||||
expect(transformedContent).toContain('](/docs/doc2');
|
||||
expect(transformedContent).toContain('](/docs/subdir/doc3');
|
||||
expect(transformedContent).toContain('](/fr/doc-localized');
|
||||
expect(transformedContent).not.toContain('](doc1.md)');
|
||||
expect(transformedContent).not.toContain('](./doc2.md)');
|
||||
expect(transformedContent).not.toContain('](subdir/doc3.md)');
|
||||
expect(transformedContent).not.toContain('](/doc-localized');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
test('transforms relative links in versioned docs', async () => {
|
||||
const doc1 = path.join(version100.contentPath, 'subdir', 'doc1.md');
|
||||
const [content, transformedContent] = await transform(doc1);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/doc2');
|
||||
expect(transformedContent).not.toContain('](../doc2.md)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
it('transforms relative links', async () => {
|
||||
const doc3 = path.join(versionCurrent.contentPath, 'subdir', 'doc3.md');
|
||||
|
||||
const [content, transformedContent] = await transform(doc3);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/doc2');
|
||||
expect(transformedContent).not.toContain('](../doc2.md)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
it('transforms reference links', async () => {
|
||||
const doc4 = path.join(versionCurrent.contentPath, 'doc4.md');
|
||||
const [content, transformedContent] = await transform(doc4);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('[doc1]: /docs/doc1');
|
||||
expect(transformedContent).toContain('[doc2]: /docs/doc2');
|
||||
expect(transformedContent).not.toContain('[doc1]: doc1.md');
|
||||
expect(transformedContent).not.toContain('[doc2]: ./doc2.md');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
it('reports broken markdown links', async () => {
|
||||
const doc5 = path.join(versionCurrent.contentPath, 'doc5.md');
|
||||
const onBrokenMarkdownLink = jest.fn();
|
||||
const [content, transformedContent] = await transform(doc5, {
|
||||
onBrokenMarkdownLink,
|
||||
});
|
||||
expect(transformedContent).toEqual(content);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenCalledTimes(4);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(1, {
|
||||
filePath: doc5,
|
||||
link: 'docNotExist1.md',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(2, {
|
||||
filePath: doc5,
|
||||
link: './docNotExist2.mdx',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(3, {
|
||||
filePath: doc5,
|
||||
link: '../docNotExist3.mdx',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
expect(onBrokenMarkdownLink).toHaveBeenNthCalledWith(4, {
|
||||
filePath: doc5,
|
||||
link: './subdir/docNotExist4.md',
|
||||
contentPaths: versionCurrent,
|
||||
} as BrokenMarkdownLink);
|
||||
});
|
||||
|
||||
it('transforms absolute links in versioned docs', async () => {
|
||||
const doc2 = path.join(version100.contentPath, 'doc2.md');
|
||||
const [content, transformedContent] = await transform(doc2);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/subdir/doc1');
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/doc2#existing-docs');
|
||||
expect(transformedContent).not.toContain('](subdir/doc1.md)');
|
||||
expect(transformedContent).not.toContain('](doc2.md#existing-docs)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
|
||||
it('transforms relative links in versioned docs', async () => {
|
||||
const doc1 = path.join(version100.contentPath, 'subdir', 'doc1.md');
|
||||
const [content, transformedContent] = await transform(doc1);
|
||||
expect(transformedContent).toMatchSnapshot();
|
||||
expect(transformedContent).toContain('](/docs/1.0.0/doc2');
|
||||
expect(transformedContent).not.toContain('](../doc2.md)');
|
||||
expect(content).not.toEqual(transformedContent);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`postProcess corrects collapsed state inconsistencies 1`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`postProcess corrects collapsed state inconsistencies 2`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`postProcess corrects collapsed state inconsistencies 3`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`postProcess transforms category without subitems 1`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"href": "version/generated/permalink",
|
||||
"label": "Category",
|
||||
"type": "link",
|
||||
},
|
||||
Object {
|
||||
"id": "doc ID",
|
||||
"label": "Category 2",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
|
@ -36,7 +36,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
});
|
||||
}
|
||||
|
||||
test('generates empty sidebar slice when no docs and emit a warning', async () => {
|
||||
it('generates empty sidebar slice when no docs and emit a warning', async () => {
|
||||
const consoleWarn = jest.spyOn(console, 'warn');
|
||||
const sidebarSlice = await testDefaultSidebarItemsGenerator({
|
||||
docs: [],
|
||||
|
@ -49,7 +49,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('generates simple flat sidebar', async () => {
|
||||
it('generates simple flat sidebar', async () => {
|
||||
const sidebarSlice = await DefaultSidebarItemsGenerator({
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
item: {
|
||||
|
@ -108,7 +108,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
expect(sidebarSlice).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('generates complex nested sidebar', async () => {
|
||||
it('generates complex nested sidebar', async () => {
|
||||
const sidebarSlice = await DefaultSidebarItemsGenerator({
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
isCategoryIndex,
|
||||
|
@ -212,7 +212,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
expect(sidebarSlice).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('generates subfolder sidebar', async () => {
|
||||
it('generates subfolder sidebar', async () => {
|
||||
// Ensure that category metadata file is correctly read
|
||||
// fix edge case found in https://github.com/facebook/docusaurus/issues/4638
|
||||
const sidebarSlice = await DefaultSidebarItemsGenerator({
|
||||
|
@ -308,7 +308,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
expect(sidebarSlice).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('uses explicit link over the index/readme.{md,mdx} naming convention', async () => {
|
||||
it('uses explicit link over the index/readme.{md,mdx} naming convention', async () => {
|
||||
const sidebarSlice = await DefaultSidebarItemsGenerator({
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
item: {
|
||||
|
@ -379,7 +379,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
expect(sidebarSlice).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('respects custom isCategoryIndex', async () => {
|
||||
it('respects custom isCategoryIndex', async () => {
|
||||
const sidebarSlice = await DefaultSidebarItemsGenerator({
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
isCategoryIndex({fileName, directories}) {
|
||||
|
@ -462,7 +462,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
expect(sidebarSlice).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('throws for unknown index link', async () => {
|
||||
it('throws for unknown index link', async () => {
|
||||
const generateSidebar = () =>
|
||||
DefaultSidebarItemsGenerator({
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {loadSidebars, DisabledSidebars} from '../index';
|
||||
import type {SidebarProcessorParams} from '../types';
|
||||
|
@ -30,19 +31,19 @@ describe('loadSidebars', () => {
|
|||
categoryLabelSlugger: null,
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
};
|
||||
test('sidebars with known sidebar item type', async () => {
|
||||
it('sidebars with known sidebar item type', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars.json');
|
||||
const result = await loadSidebars(sidebarPath, params);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('sidebars with deep level of category', async () => {
|
||||
it('sidebars with deep level of category', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-category.js');
|
||||
const result = await loadSidebars(sidebarPath, params);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('sidebars shorthand and longform lead to exact same sidebar', async () => {
|
||||
it('sidebars shorthand and longform lead to exact same sidebar', async () => {
|
||||
const sidebarPath1 = path.join(fixtureDir, 'sidebars-category.js');
|
||||
const sidebarPath2 = path.join(
|
||||
fixtureDir,
|
||||
|
@ -53,7 +54,7 @@ describe('loadSidebars', () => {
|
|||
expect(sidebar1).toEqual(sidebar2);
|
||||
});
|
||||
|
||||
test('sidebars with category but category.items is not an array', async () => {
|
||||
it('sidebars with category but category.items is not an array', async () => {
|
||||
const sidebarPath = path.join(
|
||||
fixtureDir,
|
||||
'sidebars-category-wrong-items.json',
|
||||
|
@ -65,7 +66,7 @@ describe('loadSidebars', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('sidebars with first level not a category', async () => {
|
||||
it('sidebars with first level not a category', async () => {
|
||||
const sidebarPath = path.join(
|
||||
fixtureDir,
|
||||
'sidebars-first-level-not-category.js',
|
||||
|
@ -74,35 +75,35 @@ describe('loadSidebars', () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('sidebars link', async () => {
|
||||
it('sidebars link', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-link.json');
|
||||
const result = await loadSidebars(sidebarPath, params);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('unexisting path', async () => {
|
||||
it('unexisting path', async () => {
|
||||
await expect(loadSidebars('badpath', params)).resolves.toEqual(
|
||||
DisabledSidebars,
|
||||
);
|
||||
});
|
||||
|
||||
test('undefined path', async () => {
|
||||
it('undefined path', async () => {
|
||||
await expect(loadSidebars(undefined, params)).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('literal false path', async () => {
|
||||
it('literal false path', async () => {
|
||||
await expect(loadSidebars(false, params)).resolves.toEqual(
|
||||
DisabledSidebars,
|
||||
);
|
||||
});
|
||||
|
||||
test('sidebars with category.collapsed property', async () => {
|
||||
it('sidebars with category.collapsed property', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json');
|
||||
const result = await loadSidebars(sidebarPath, params);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('sidebars with category.collapsed property at first level', async () => {
|
||||
it('sidebars with category.collapsed property at first level', async () => {
|
||||
const sidebarPath = path.join(
|
||||
fixtureDir,
|
||||
'sidebars-collapsed-first-level.json',
|
||||
|
@ -111,7 +112,7 @@ describe('loadSidebars', () => {
|
|||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('duplicate category metadata files', async () => {
|
||||
it('duplicate category metadata files', async () => {
|
||||
const sidebarPath = path.join(
|
||||
fixtureDir,
|
||||
'sidebars-collapsed-first-level.json',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import {normalizeSidebars} from '../normalization';
|
||||
|
||||
describe('normalization', () => {
|
||||
test('normalizes shorthands', () => {
|
||||
it('normalizes shorthands', () => {
|
||||
expect(
|
||||
normalizeSidebars({
|
||||
sidebar: {
|
||||
|
@ -37,7 +37,7 @@ describe('normalization', () => {
|
|||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
test('rejects some invalid cases', () => {
|
||||
it('rejects some invalid cases', () => {
|
||||
expect(() =>
|
||||
normalizeSidebars({
|
||||
sidebar: {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import {postProcessSidebars} from '../postProcessor';
|
||||
|
||||
describe('postProcess', () => {
|
||||
test('transforms category without subitems', () => {
|
||||
it('transforms category without subitems', () => {
|
||||
const processedSidebar = postProcessSidebars(
|
||||
{
|
||||
sidebar: [
|
||||
|
@ -38,22 +38,7 @@ describe('postProcess', () => {
|
|||
},
|
||||
);
|
||||
|
||||
expect(processedSidebar).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"href": "version/generated/permalink",
|
||||
"label": "Category",
|
||||
"type": "link",
|
||||
},
|
||||
Object {
|
||||
"id": "doc ID",
|
||||
"label": "Category 2",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
expect(processedSidebar).toMatchSnapshot();
|
||||
|
||||
expect(() => {
|
||||
postProcessSidebars(
|
||||
|
@ -76,7 +61,7 @@ describe('postProcess', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('corrects collapsed state inconsistencies', () => {
|
||||
it('corrects collapsed state inconsistencies', () => {
|
||||
expect(
|
||||
postProcessSidebars(
|
||||
{
|
||||
|
@ -96,25 +81,7 @@ describe('postProcess', () => {
|
|||
version: {versionPath: 'version'},
|
||||
},
|
||||
),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
).toMatchSnapshot();
|
||||
|
||||
expect(
|
||||
postProcessSidebars(
|
||||
|
@ -134,25 +101,7 @@ describe('postProcess', () => {
|
|||
version: {versionPath: 'version'},
|
||||
},
|
||||
),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
).toMatchSnapshot();
|
||||
|
||||
expect(
|
||||
postProcessSidebars(
|
||||
|
@ -171,24 +120,6 @@ describe('postProcess', () => {
|
|||
version: {versionPath: 'version'},
|
||||
},
|
||||
),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"collapsed": false,
|
||||
"collapsible": false,
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "foo",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"link": undefined,
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -66,7 +66,7 @@ describe('processSidebars', () => {
|
|||
});
|
||||
}
|
||||
|
||||
test('let sidebars without autogenerated items untouched', async () => {
|
||||
it('leaves sidebars without autogenerated items untouched', async () => {
|
||||
const unprocessedSidebars: NormalizedSidebars = {
|
||||
someSidebar: [
|
||||
{type: 'doc', id: 'doc1'},
|
||||
|
@ -96,7 +96,7 @@ describe('processSidebars', () => {
|
|||
expect(processedSidebar).toEqual(unprocessedSidebars);
|
||||
});
|
||||
|
||||
test('replace autogenerated items by generated sidebars slices', async () => {
|
||||
it('replaces autogenerated items by generated sidebars slices', async () => {
|
||||
const unprocessedSidebars: NormalizedSidebars = {
|
||||
someSidebar: [
|
||||
{type: 'doc', id: 'doc1'},
|
||||
|
@ -199,7 +199,7 @@ describe('processSidebars', () => {
|
|||
} as ProcessedSidebars);
|
||||
});
|
||||
|
||||
test('ensure generated items are normalized', async () => {
|
||||
it('ensures generated items are normalized', async () => {
|
||||
const sidebarSliceContainingCategoryGeneratedIndex: NormalizedSidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
|
|
@ -131,11 +131,11 @@ describe('createSidebarsUtils', () => {
|
|||
getFirstLink,
|
||||
} = createSidebarsUtils(sidebars);
|
||||
|
||||
test('getFirstDocIdOfFirstSidebar', async () => {
|
||||
it('getFirstDocIdOfFirstSidebar', async () => {
|
||||
expect(getFirstDocIdOfFirstSidebar()).toEqual('doc1');
|
||||
});
|
||||
|
||||
test('getSidebarNameByDocId', async () => {
|
||||
it('getSidebarNameByDocId', async () => {
|
||||
expect(getSidebarNameByDocId('doc1')).toEqual('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc2')).toEqual('sidebar1');
|
||||
expect(getSidebarNameByDocId('doc3')).toEqual('sidebar2');
|
||||
|
@ -146,7 +146,7 @@ describe('createSidebarsUtils', () => {
|
|||
expect(getSidebarNameByDocId('unknown_id')).toEqual(undefined);
|
||||
});
|
||||
|
||||
test('getDocNavigation', async () => {
|
||||
it('getDocNavigation', async () => {
|
||||
expect(getDocNavigation('doc1', 'doc1', undefined)).toEqual({
|
||||
sidebarName: 'sidebar1',
|
||||
previous: undefined,
|
||||
|
@ -226,7 +226,7 @@ describe('createSidebarsUtils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('getCategoryGeneratedIndexNavigation', async () => {
|
||||
it('getCategoryGeneratedIndexNavigation', async () => {
|
||||
expect(
|
||||
getCategoryGeneratedIndexNavigation('/s3-subcategory-index-permalink'),
|
||||
).toMatchObject({
|
||||
|
@ -256,7 +256,7 @@ describe('createSidebarsUtils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('getCategoryGeneratedIndexList', async () => {
|
||||
it('getCategoryGeneratedIndexList', async () => {
|
||||
expect(getCategoryGeneratedIndexList()).toMatchObject([
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -273,7 +273,7 @@ describe('createSidebarsUtils', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('getFirstLink', () => {
|
||||
it('getFirstLink', () => {
|
||||
expect(getFirstLink('sidebar1')).toEqual({
|
||||
id: 'doc1',
|
||||
type: 'doc',
|
||||
|
@ -298,7 +298,7 @@ describe('createSidebarsUtils', () => {
|
|||
});
|
||||
|
||||
describe('collectSidebarDocItems', () => {
|
||||
test('can collect docs', async () => {
|
||||
it('can collect docs', async () => {
|
||||
const sidebar: Sidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -354,7 +354,7 @@ describe('collectSidebarDocItems', () => {
|
|||
});
|
||||
|
||||
describe('collectSidebarCategories', () => {
|
||||
test('can collect categories', async () => {
|
||||
it('can collect categories', async () => {
|
||||
const sidebar: Sidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -412,7 +412,7 @@ describe('collectSidebarCategories', () => {
|
|||
});
|
||||
|
||||
describe('collectSidebarLinks', () => {
|
||||
test('can collect links', async () => {
|
||||
it('can collect links', async () => {
|
||||
const sidebar: Sidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -450,7 +450,7 @@ describe('collectSidebarLinks', () => {
|
|||
});
|
||||
|
||||
describe('collectSidebarsDocIds', () => {
|
||||
test('can collect sidebars doc items', async () => {
|
||||
it('can collect sidebars doc items', async () => {
|
||||
const sidebar1: Sidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -496,7 +496,7 @@ describe('collectSidebarsDocIds', () => {
|
|||
});
|
||||
|
||||
describe('transformSidebarItems', () => {
|
||||
test('can transform sidebar items', async () => {
|
||||
it('can transform sidebar items', async () => {
|
||||
const sidebar: Sidebar = [
|
||||
{
|
||||
type: 'category',
|
||||
|
@ -606,7 +606,7 @@ describe('toDocNavigationLink', () => {
|
|||
return data as DocMetadataBase;
|
||||
}
|
||||
|
||||
test('with no front matter', () => {
|
||||
it('with no front matter', () => {
|
||||
expect(
|
||||
toDocNavigationLink(
|
||||
testDoc({
|
||||
|
@ -621,7 +621,7 @@ describe('toDocNavigationLink', () => {
|
|||
} as DocNavLink);
|
||||
});
|
||||
|
||||
test('with pagination_label front matter', () => {
|
||||
it('with pagination_label front matter', () => {
|
||||
expect(
|
||||
toDocNavigationLink(
|
||||
testDoc({
|
||||
|
@ -638,7 +638,7 @@ describe('toDocNavigationLink', () => {
|
|||
} as DocNavLink);
|
||||
});
|
||||
|
||||
test('with sidebar_label front matter', () => {
|
||||
it('with sidebar_label front matter', () => {
|
||||
expect(
|
||||
toDocNavigationLink(
|
||||
testDoc({
|
||||
|
@ -655,7 +655,7 @@ describe('toDocNavigationLink', () => {
|
|||
} as DocNavLink);
|
||||
});
|
||||
|
||||
test('with pagination_label + sidebar_label front matter', () => {
|
||||
it('with pagination_label + sidebar_label front matter', () => {
|
||||
expect(
|
||||
toDocNavigationLink(
|
||||
testDoc({
|
||||
|
@ -691,7 +691,7 @@ describe('toNavigationLink', () => {
|
|||
}),
|
||||
};
|
||||
|
||||
test('with doc items', () => {
|
||||
it('with doc items', () => {
|
||||
expect(toNavigationLink({type: 'doc', id: 'doc1'}, docsById)).toEqual(
|
||||
toDocNavigationLink(docsById.doc1),
|
||||
);
|
||||
|
@ -705,7 +705,7 @@ describe('toNavigationLink', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('with category item and doc link', () => {
|
||||
it('with category item and doc link', () => {
|
||||
expect(
|
||||
toNavigationLink(
|
||||
{
|
||||
|
@ -742,7 +742,7 @@ describe('toNavigationLink', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('with category item and generated-index link', () => {
|
||||
it('with category item and generated-index link', () => {
|
||||
expect(
|
||||
toNavigationLink(
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ import {validateSidebars, validateCategoryMetadataFile} from '../validation';
|
|||
import type {SidebarsConfig, CategoryMetadataFile} from '../types';
|
||||
|
||||
describe('validateSidebars', () => {
|
||||
test('throw for bad value', async () => {
|
||||
it('throw for bad value', async () => {
|
||||
expect(() => validateSidebars({sidebar: [{type: 42}]}))
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"{
|
||||
|
@ -21,12 +21,12 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('accept empty object', async () => {
|
||||
it('accept empty object', async () => {
|
||||
const sidebars: SidebarsConfig = {};
|
||||
validateSidebars(sidebars);
|
||||
});
|
||||
|
||||
test('accept valid values', async () => {
|
||||
it('accept valid values', async () => {
|
||||
const sidebars: SidebarsConfig = {
|
||||
sidebar1: [
|
||||
{type: 'doc', id: 'doc1'},
|
||||
|
@ -41,17 +41,19 @@ describe('validateSidebars', () => {
|
|||
validateSidebars(sidebars);
|
||||
});
|
||||
|
||||
test('sidebar category wrong label', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
{
|
||||
type: 'category',
|
||||
label: true,
|
||||
items: [{type: 'doc', id: 'doc1'}],
|
||||
},
|
||||
],
|
||||
}),
|
||||
it('sidebar category wrong label', () => {
|
||||
expect(
|
||||
() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
{
|
||||
type: 'category',
|
||||
label: true,
|
||||
items: [{type: 'doc', id: 'doc1'}],
|
||||
},
|
||||
],
|
||||
}),
|
||||
// eslint-disable-next-line jest/no-large-snapshots
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"{
|
||||
\\"type\\": \\"category\\",
|
||||
|
@ -68,7 +70,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebars link wrong label', () => {
|
||||
it('sidebars link wrong label', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -90,7 +92,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebars link wrong href', () => {
|
||||
it('sidebars link wrong href', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -114,7 +116,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebars with unknown sidebar item type', () => {
|
||||
it('sidebars with unknown sidebar item type', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -133,7 +135,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebars category missing items', () => {
|
||||
it('sidebars category missing items', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -159,7 +161,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebars category wrong field', () => {
|
||||
it('sidebars category wrong field', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -188,7 +190,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('sidebar category wrong items', () => {
|
||||
it('sidebar category wrong items', () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: {
|
||||
|
@ -204,7 +206,7 @@ describe('validateSidebars', () => {
|
|||
).toThrowErrorMatchingInlineSnapshot(`"sidebar.forEach is not a function"`);
|
||||
});
|
||||
|
||||
test('sidebars item doc but id is not a string', async () => {
|
||||
it('sidebars item doc but id is not a string', async () => {
|
||||
expect(() =>
|
||||
validateSidebars({
|
||||
docs: [
|
||||
|
@ -226,7 +228,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('HTML type requires a value', () => {
|
||||
it('hTML type requires a value', () => {
|
||||
const sidebars: SidebarsConfig = {
|
||||
sidebar1: [
|
||||
{
|
||||
|
@ -246,7 +248,7 @@ describe('validateSidebars', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('HTML type accepts valid values', () => {
|
||||
it('hTML type accepts valid values', () => {
|
||||
const sidebars: SidebarsConfig = {
|
||||
sidebar1: [
|
||||
{
|
||||
|
@ -264,7 +266,7 @@ describe('validateSidebars', () => {
|
|||
describe('validateCategoryMetadataFile', () => {
|
||||
// TODO add more tests
|
||||
|
||||
test('throw for bad value', async () => {
|
||||
it('throw for bad value', async () => {
|
||||
expect(() =>
|
||||
validateCategoryMetadataFile(42),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
|
@ -272,12 +274,12 @@ describe('validateCategoryMetadataFile', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('accept empty object', async () => {
|
||||
it('accept empty object', async () => {
|
||||
const content: CategoryMetadataFile = {};
|
||||
expect(validateCategoryMetadataFile(content)).toEqual(content);
|
||||
});
|
||||
|
||||
test('accept valid values', async () => {
|
||||
it('accept valid values', async () => {
|
||||
const content: CategoryMetadataFile = {
|
||||
className: 'className',
|
||||
label: 'Category Label',
|
||||
|
@ -294,7 +296,7 @@ describe('validateCategoryMetadataFile', () => {
|
|||
expect(validateCategoryMetadataFile(content)).toEqual(content);
|
||||
});
|
||||
|
||||
test('rejects permalink', async () => {
|
||||
it('rejects permalink', async () => {
|
||||
const content: CategoryMetadataFile = {
|
||||
className: 'className',
|
||||
label: 'Category Label',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue