mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 14:06:59 +02:00
refactor(v2): cleanup console output (#4979)
* refactor(v2): cleanup console output * fix jest issue Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
8501db78a1
commit
41d9288e3d
86 changed files with 382 additions and 339 deletions
|
@ -1,11 +1,11 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`sidebar site with wrong sidebar content 1`] = `
|
||||
"Bad sidebar file at 'packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json'.
|
||||
"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,
|
||||
- goku
|
||||
|
||||
Available document ids=
|
||||
Available document ids are:
|
||||
- foo/bar
|
||||
- foo/baz
|
||||
- headingAsTitle
|
||||
|
|
|
@ -35,7 +35,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0"`,
|
||||
`"[docs]: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -45,7 +45,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0"`,
|
||||
`"[docs]: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -55,7 +55,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] No version tag specified!. Pass the version you wish to create as an argument. Ex: 1.0.0"`,
|
||||
`"[docs]: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Do not include slash (/) or (\\\\). Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Do not include slash (/) or backslash (\\\\). Try something like: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -78,7 +78,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Do not include slash (/) or (\\\\). Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Do not include slash (/) or backslash (\\\\). Try something like: 1.0.0."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -91,7 +91,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Length must <= 32 characters. Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -104,7 +104,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Do not name your version \\".\\" or \\"..\\". Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Do not name your version \\".\\" or \\"..\\". Try something like: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -114,7 +114,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Do not name your version \\".\\" or \\"..\\". Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Do not name your version \\".\\" or \\"..\\". Try something like: 1.0.0."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -137,7 +137,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0."`,
|
||||
);
|
||||
expect(() =>
|
||||
cliDocsVersionCommand(
|
||||
|
@ -147,7 +147,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] Invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0"`,
|
||||
`"[docs]: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -160,7 +160,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] This version already exists!. Use a version tag that does not already exist."`,
|
||||
`"[docs]: this version already exists! Use a version tag that does not already exist."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -174,7 +174,7 @@ describe('docsVersion', () => {
|
|||
DEFAULT_OPTIONS,
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"[docs] There is no docs to version !"`,
|
||||
`"[docs]: there is no docs to version!"`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -218,7 +218,7 @@ describe('docsVersion', () => {
|
|||
getVersionsFilePath(simpleSiteDir, DEFAULT_PLUGIN_ID),
|
||||
);
|
||||
expect(versions).toEqual(['1.0.0']);
|
||||
expect(consoleMock).toHaveBeenCalledWith('[docs] Version 1.0.0 created!');
|
||||
expect(consoleMock).toHaveBeenCalledWith('[docs]: version 1.0.0 created!');
|
||||
|
||||
copyMock.mockRestore();
|
||||
writeMock.mockRestore();
|
||||
|
@ -271,7 +271,7 @@ describe('docsVersion', () => {
|
|||
getVersionsFilePath(versionedSiteDir, DEFAULT_PLUGIN_ID),
|
||||
);
|
||||
expect(versions).toEqual(['2.0.0', '1.0.1', '1.0.0', 'withSlugs']);
|
||||
expect(consoleMock).toHaveBeenCalledWith('[docs] Version 2.0.0 created!');
|
||||
expect(consoleMock).toHaveBeenCalledWith('[docs]: version 2.0.0 created!');
|
||||
|
||||
copyMock.mockRestore();
|
||||
writeMock.mockRestore();
|
||||
|
@ -322,7 +322,7 @@ describe('docsVersion', () => {
|
|||
);
|
||||
expect(versions).toEqual(['2.0.0', '1.0.0']);
|
||||
expect(consoleMock).toHaveBeenCalledWith(
|
||||
'[community] Version 2.0.0 created!',
|
||||
'[community]: version 2.0.0 created!',
|
||||
);
|
||||
|
||||
copyMock.mockRestore();
|
||||
|
|
|
@ -453,7 +453,7 @@ describe('simple site', () => {
|
|||
}),
|
||||
);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Document id [Hello/world] cannot include \\"/\\"."`,
|
||||
`"Document id \\"Hello/world\\" cannot include slash."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -44,8 +44,10 @@ function getDocById(version: LoadedVersion, unversionedId: string) {
|
|||
const doc = findDocById(version, unversionedId);
|
||||
if (!doc) {
|
||||
throw new Error(
|
||||
`No doc found with id=${unversionedId} in version ${version.versionName}.
|
||||
Available ids=\n- ${version.docs.map((d) => d.unversionedId).join('\n- ')}`,
|
||||
`No doc found with id "${unversionedId}" in version ${
|
||||
version.versionName
|
||||
}.
|
||||
Available ids are:\n- ${version.docs.map((d) => d.unversionedId).join('\n- ')}`,
|
||||
);
|
||||
}
|
||||
return doc;
|
||||
|
@ -85,7 +87,7 @@ const createFakeActions = (contentDir: string) => {
|
|||
key.startsWith(prefix),
|
||||
);
|
||||
if (!entry) {
|
||||
throw new Error(`No created entry found for prefix=[${prefix}]
|
||||
throw new Error(`No created entry found for prefix "${prefix}".
|
||||
Entries created:
|
||||
- ${Object.keys(dataContainer).join('\n- ')}
|
||||
`);
|
||||
|
@ -151,8 +153,8 @@ describe('sidebar', () => {
|
|||
);
|
||||
await plugin.loadContent!();
|
||||
}).rejects.toThrowErrorMatchingInlineSnapshot(`
|
||||
"The path to the sidebar file does not exist at [wrong-path-sidebar.json].
|
||||
Please set the docs [sidebarPath] field in your config file to:
|
||||
"The path to the sidebar file does not exist at \\"wrong-path-sidebar.json\\".
|
||||
Please set the docs \\"sidebarPath\\" field in your config file to:
|
||||
- a sidebars path that exists
|
||||
- false: to disable the sidebar
|
||||
- undefined: for Docusaurus generates it automatically"
|
||||
|
@ -217,7 +219,7 @@ describe('empty/no docs website', () => {
|
|||
await expect(
|
||||
plugin.loadContent!(),
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Docs version current has no docs! At least one doc should exist at path=[docs]"`,
|
||||
`"Docs version \\"current\\" has no docs! At least one doc should exist at \\"docs\\"."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -231,11 +233,11 @@ describe('empty/no docs website', () => {
|
|||
}),
|
||||
),
|
||||
).toThrowError(
|
||||
`The docs folder does not exist for version [current]. A docs folder is expected to be found at ${
|
||||
`The docs folder does not exist for version "current". A docs folder is expected to be found at ${
|
||||
process.platform === 'win32'
|
||||
? 'path\\doesnt\\exist'
|
||||
: 'path/doesnt/exist'
|
||||
}`,
|
||||
}.`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ describe('loadSidebars', () => {
|
|||
'sidebars-category-wrong-items.json',
|
||||
);
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error loading {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}. \\"items\\" must be an array."`,
|
||||
`"Error loading {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}: \\"items\\" must be an array."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -70,7 +70,7 @@ describe('loadSidebars', () => {
|
|||
'sidebars-category-wrong-label.json',
|
||||
);
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error loading {\\"type\\":\\"category\\",\\"label\\":true,\\"items\\":[\\"doc1\\"]}. \\"label\\" must be a string."`,
|
||||
`"Error loading {\\"type\\":\\"category\\",\\"label\\":true,\\"items\\":[\\"doc1\\"]}: \\"label\\" must be a string."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -80,7 +80,7 @@ describe('loadSidebars', () => {
|
|||
'sidebars-doc-id-not-string.json',
|
||||
);
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error loading {\\"type\\":\\"doc\\",\\"id\\":[\\"doc1\\"]}. \\"id\\" must be a string."`,
|
||||
`"Error loading {\\"type\\":\\"doc\\",\\"id\\":[\\"doc1\\"]}: \\"id\\" must be a string."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -102,22 +102,23 @@ describe('loadSidebars', () => {
|
|||
test('sidebars link wrong label', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-label.json');
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error loading {\\"type\\":\\"link\\",\\"label\\":false,\\"href\\":\\"https://github.com\\"}. \\"label\\" must be a string."`,
|
||||
`"Error loading {\\"type\\":\\"link\\",\\"label\\":false,\\"href\\":\\"https://github.com\\"}: \\"label\\" must be a string."`,
|
||||
);
|
||||
});
|
||||
|
||||
test('sidebars link wrong href', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-href.json');
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Error loading {\\"type\\":\\"link\\",\\"label\\":\\"GitHub\\",\\"href\\":[\\"example.com\\"]}. \\"href\\" must be a string."`,
|
||||
`"Error loading {\\"type\\":\\"link\\",\\"label\\":\\"GitHub\\",\\"href\\":[\\"example.com\\"]}: \\"href\\" must be a string."`,
|
||||
);
|
||||
});
|
||||
|
||||
test('sidebars with unknown sidebar item type', async () => {
|
||||
const sidebarPath = path.join(fixtureDir, 'sidebars-unknown-type.json');
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Unknown sidebar item type [superman]. Sidebar item={\\"type\\":\\"superman\\"} "`,
|
||||
);
|
||||
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(`
|
||||
"Unknown sidebar item type \\"superman\\". Sidebar item is {\\"type\\":\\"superman\\"}.
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
test('sidebars with known sidebar item type but wrong field', async () => {
|
||||
|
|
|
@ -174,7 +174,7 @@ describe('simple site', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Bad docs options.versions: unknown versions found: unknownVersionName1,unknownVersionName2. Available version names are: current"`,
|
||||
`"Invalid docs option \\"versions\\": unknown versions (unknownVersionName1,unknownVersionName2) found. Available version names are: current"`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -187,7 +187,7 @@ describe('simple site', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Docs: using disableVersioning=true option on a non-versioned site does not make sense"`,
|
||||
`"Docs: using \\"disableVersioning=true\\" option on a non-versioned site does not make sense."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -200,7 +200,7 @@ describe('simple site', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=false"`,
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=false\\"."`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -527,7 +527,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=true"`,
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=true\\"."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -543,7 +543,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Bad docs options.onlyIncludeVersions: an empty array is not allowed, at least one version is needed"`,
|
||||
`"Invalid docs option \\"onlyIncludeVersions\\": an empty array is not allowed, at least one version is needed."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -559,7 +559,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Bad docs options.onlyIncludeVersions: unknown versions found: unknownVersion1,unknownVersion2. Available version names are: current, 1.0.1, 1.0.0, withSlugs"`,
|
||||
`"Invalid docs option \\"onlyIncludeVersions\\": unknown versions (unknownVersion1,unknownVersion2) found. Available version names are: current, 1.0.1, 1.0.0, withSlugs"`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -576,7 +576,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Bad docs options.lastVersion: if you use both the onlyIncludeVersions and lastVersion options, then lastVersion must be present in the provided onlyIncludeVersions array"`,
|
||||
`"Invalid docs option \\"lastVersion\\": if you use both the \\"onlyIncludeVersions\\" and \\"lastVersion\\" options, then \\"lastVersion\\" must be present in the provided \\"onlyIncludeVersions\\" array."`,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -595,7 +595,7 @@ describe('versioned site, pluginId=default', () => {
|
|||
context: defaultContext,
|
||||
});
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"The versions file should contain an array of versions! Found content={\\"invalid\\":\\"json\\"}"`,
|
||||
`"The versions file should contain an array of versions! Found content: {\\"invalid\\":\\"json\\"}"`,
|
||||
);
|
||||
mock.mockRestore();
|
||||
});
|
||||
|
@ -712,7 +712,7 @@ describe('versioned site, pluginId=community', () => {
|
|||
context: defaultContext,
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=true"`,
|
||||
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=true\\"."`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue