chore: disable string escaping in snapshots (#7131)

This commit is contained in:
Joshua Chen 2022-04-08 11:23:19 +08:00 committed by GitHub
parent 4134ebb3fb
commit 9145ae88cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 1881 additions and 1884 deletions

View file

@ -82,12 +82,12 @@ describe('docsVersion', () => {
await expect(() =>
cliDocsVersionCommand('..', DEFAULT_OPTIONS, {siteDir: simpleSiteDir}),
).rejects.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."`,
);
await expect(() =>
cliDocsVersionCommand('.', DEFAULT_OPTIONS, {siteDir: simpleSiteDir}),
).rejects.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."`,
);
});
@ -133,7 +133,7 @@ describe('docsVersion', () => {
i18n: {locales: ['en', 'zh-Hans'], defaultLocale: 'en'},
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"[docs]: no docs found in \\"<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/empty-site/docs\\"."`,
`"[docs]: no docs found in "<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/empty-site/docs"."`,
);
});
@ -249,7 +249,7 @@ describe('docsVersion', () => {
),
);
expect(warnMock.mock.calls[0][0]).toMatchInlineSnapshot(
`"[WARNING] [docs]: no docs found in \\"<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/versioned-site/i18n/zh-Hans/docusaurus-plugin-content-docs/current\\". Skipping."`,
`"[WARNING] [docs]: no docs found in "<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/versioned-site/i18n/zh-Hans/docusaurus-plugin-content-docs/current". Skipping."`,
);
warnMock.mockRestore();

View file

@ -487,7 +487,7 @@ describe('simple site', () => {
}),
),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Document id \\"Hello/world\\" cannot include slash."`,
`"Document id "Hello/world" cannot include slash."`,
);
});

View file

@ -143,10 +143,11 @@ 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 to generate it automatically"
@ -203,7 +204,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 \\"docs\\"."`,
`"Docs version "current" has no docs! At least one doc should exist at "docs"."`,
);
});
@ -220,7 +221,7 @@ describe('empty/no docs website', () => {
}),
),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The docs folder does not exist for version \\"current\\". A docs folder is expected to be found at path/does/not/exist."`,
`"The docs folder does not exist for version "current". A docs folder is expected to be found at path/does/not/exist."`,
);
});
});

View file

@ -117,7 +117,7 @@ describe('normalizeDocsPluginOptions', () => {
expect(() =>
testValidate(admonitionsTrue),
).toThrowErrorMatchingInlineSnapshot(
`"\\"admonitions\\" contains an invalid value"`,
`""admonitions" contains an invalid value"`,
);
});
@ -151,9 +151,9 @@ describe('normalizeDocsPluginOptions', () => {
remarkPlugins: [[{option1: '42'}, markdownPluginsFunctionStub]],
}),
).toThrowErrorMatchingInlineSnapshot(`
"\\"remarkPlugins[0]\\" does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require(\\"rehype-katex\\"), { strict: false }]\`, or
- A simple module, like \`require(\\"remark-math\\")\`"
""remarkPlugins[0]" does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require("rehype-katex"), { strict: false }]\`, or
- A simple module, like \`require("remark-math")\`"
`);
});
@ -169,46 +169,42 @@ describe('normalizeDocsPluginOptions', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(`
"\\"rehypePlugins[0]\\" does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require(\\"rehype-katex\\"), { strict: false }]\`, or
- A simple module, like \`require(\\"remark-math\\")\`"
""rehypePlugins[0]" does not look like a valid MDX plugin config. A plugin config entry should be one of:
- A tuple, like \`[require("rehype-katex"), { strict: false }]\`, or
- A simple module, like \`require("remark-math")\`"
`);
});
it('rejects bad path inputs', () => {
expect(() => testValidate({path: 2})).toThrowErrorMatchingInlineSnapshot(
`"\\"path\\" must be a string"`,
`""path" must be a string"`,
);
});
it('rejects bad include inputs', () => {
expect(() =>
testValidate({include: '**/*.{md,mdx}'}),
).toThrowErrorMatchingInlineSnapshot(`"\\"include\\" must be an array"`);
).toThrowErrorMatchingInlineSnapshot(`""include" must be an array"`);
});
it('rejects bad showLastUpdateTime inputs', () => {
expect(() =>
testValidate({showLastUpdateTime: 'true'}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"showLastUpdateTime\\" must be a boolean"`,
`""showLastUpdateTime" must be a boolean"`,
);
});
it('rejects bad remarkPlugins input', () => {
expect(() =>
testValidate({remarkPlugins: 'remark-math'}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"remarkPlugins\\" must be an array"`,
);
).toThrowErrorMatchingInlineSnapshot(`""remarkPlugins" must be an array"`);
});
it('rejects bad lastVersion', () => {
expect(() =>
testValidate({lastVersion: false}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"lastVersion\\" must be a string"`,
);
).toThrowErrorMatchingInlineSnapshot(`""lastVersion" must be a string"`);
});
it('rejects bad versions', () => {
@ -218,6 +214,7 @@ describe('normalizeDocsPluginOptions', () => {
current: {
hey: 3,
},
version1: {
path: 'hello',
label: 'world',
@ -225,7 +222,7 @@ describe('normalizeDocsPluginOptions', () => {
},
}),
).toThrowErrorMatchingInlineSnapshot(
`"\\"versions.current.hey\\" is not allowed"`,
`""versions.current.hey" is not allowed"`,
);
});

View file

@ -120,7 +120,7 @@ describe('getSlug', () => {
frontMatterSlug: '//',
}),
).toThrowErrorMatchingInlineSnapshot(`
"We couldn't compute a valid slug for document with ID \\"my dôc\\" in \\"/dir with spâce/hey $hello\\" directory.
"We couldn't compute a valid slug for document with ID "my dôc" in "/dir with spâce/hey $hello" directory.
The slug we computed looks invalid: //.
Maybe your slug front matter is incorrect or there are special characters in the file path?
By using front matter to set a custom slug, you should be able to fix this error:

View file

@ -187,10 +187,11 @@ describe('readVersionsMetadata', () => {
unknownVersionName2: {label: 'unknownVersionName2'},
},
},
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid docs option \\"versions\\": unknown versions (unknownVersionName1,unknownVersionName2) found. Available version names are: current"`,
`"Invalid docs option "versions": unknown versions (unknownVersionName1,unknownVersionName2) found. Available version names are: current"`,
);
});
@ -203,7 +204,7 @@ describe('readVersionsMetadata', () => {
context: defaultContext,
}),
).rejects.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."`,
);
});
@ -216,7 +217,7 @@ describe('readVersionsMetadata', () => {
context: defaultContext,
}),
).rejects.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"."`,
);
});
});
@ -557,10 +558,11 @@ describe('readVersionsMetadata', () => {
includeCurrentVersion: false,
disableVersioning: true,
},
context: defaultContext,
}),
).rejects.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"."`,
);
});
@ -573,10 +575,11 @@ describe('readVersionsMetadata', () => {
...defaultOptions,
onlyIncludeVersions: [],
},
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid docs option \\"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."`,
);
});
@ -589,10 +592,11 @@ describe('readVersionsMetadata', () => {
...defaultOptions,
onlyIncludeVersions: ['unknownVersion1', 'unknownVersion2'],
},
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid docs option \\"onlyIncludeVersions\\": unknown versions (unknownVersion1,unknownVersion2) found. 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"`,
);
});
@ -606,10 +610,11 @@ describe('readVersionsMetadata', () => {
lastVersion: '1.0.1',
onlyIncludeVersions: ['current', '1.0.0'],
},
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid docs option \\"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."`,
);
});
@ -627,7 +632,7 @@ describe('readVersionsMetadata', () => {
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The versions file should contain an array of version names! Found content: {\\"invalid\\":\\"json\\"}"`,
`"The versions file should contain an array of version names! Found content: {"invalid":"json"}"`,
);
jsonMock.mockImplementationOnce(() => [1.1]);
@ -637,7 +642,7 @@ describe('readVersionsMetadata', () => {
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Versions should be strings. Found type \\"number\\" for version \\"1.1\\"."`,
`"Versions should be strings. Found type "number" for version "1.1"."`,
);
jsonMock.mockImplementationOnce(() => [' ']);
@ -646,9 +651,7 @@ describe('readVersionsMetadata', () => {
options: defaultOptions,
context: defaultContext,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid version \\" \\"."`,
);
).rejects.toThrowErrorMatchingInlineSnapshot(`"Invalid version " "."`);
jsonMock.mockRestore();
});
});
@ -772,10 +775,11 @@ describe('readVersionsMetadata', () => {
includeCurrentVersion: false,
disableVersioning: true,
},
context: defaultContext,
}),
).rejects.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"."`,
);
});
});

View file

@ -38,12 +38,12 @@ describe('docsClientUtils', () => {
expect(() =>
getActivePlugin(data, '/', {failfast: true}),
).toThrowErrorMatchingInlineSnapshot(
`"Can't find active docs plugin for \\"/\\" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
`"Can't find active docs plugin for "/" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
);
expect(() =>
getActivePlugin(data, '/xyz', {failfast: true}),
).toThrowErrorMatchingInlineSnapshot(
`"Can't find active docs plugin for \\"/xyz\\" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
`"Can't find active docs plugin for "/xyz" pathname, while it was expected to be found. Maybe you tried to use a docs feature that can only be used on a docs-related page? Existing docs plugin paths are: /ios, /android"`,
);
const activePluginIos: ActivePlugin = {

View file

@ -200,7 +200,7 @@ describe('linkify', () => {
await expect(() =>
transform(doc1),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unexpected error: Markdown file at \\"<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/markdown/__tests__/__fixtures__/outside/doc1.md\\" does not belong to any docs version!"`,
`"Unexpected error: Markdown file at "<PROJECT_ROOT>/packages/docusaurus-plugin-content-docs/src/markdown/__tests__/__fixtures__/outside/doc1.md" does not belong to any docs version!"`,
);
});
});

View file

@ -62,7 +62,7 @@ describe('loadSidebars', () => {
await expect(() =>
loadSidebars(sidebarPath, params),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`\\"doc1\\"\` in \`items\` of the category Category Label: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
`"Invalid sidebar items collection \`"doc1"\` in \`items\` of the category Category Label: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
});
@ -131,7 +131,7 @@ describe('loadSidebars', () => {
contentPathLocalized: path.join(fixtureDir, 'invalid-docs'),
},
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`"\\"foo\\" is not allowed"`);
).rejects.toThrowErrorMatchingInlineSnapshot(`""foo" is not allowed"`);
expect(consoleWarnMock).toBeCalledWith(
expect.stringMatching(
/.*\[WARNING\].* There are more than one category metadata files for .*foo.*: foo\/_category_.json, foo\/_category_.yml. The behavior is undetermined./,

View file

@ -46,7 +46,7 @@ describe('normalization', () => {
},
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{\\"type\\":\\"autogenerated\\",\\"dirName\\":\\"foo\\"}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
`"Invalid sidebar items collection \`{"type":"autogenerated","dirName":"foo"}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
@ -62,7 +62,7 @@ describe('normalization', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{\\"type\\":\\"category\\",\\"items\\":[\\"bar\\",\\"baz\\"]}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
`"Invalid sidebar items collection \`{"type":"category","items":["bar","baz"]}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
@ -75,7 +75,7 @@ describe('normalization', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`\\"bar\\"\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
`"Invalid sidebar items collection \`"bar"\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
@ -83,8 +83,7 @@ describe('normalization', () => {
sidebar: 'item',
}),
).toThrowErrorMatchingInlineSnapshot(
// cSpell:ignore msidebar
`"Invalid sidebar items collection \`\\"item\\"\` in sidebar sidebar: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
`"Invalid sidebar items collection \`"item"\` in sidebar sidebar: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
});
});

View file

@ -13,11 +13,11 @@ describe('validateSidebars', () => {
expect(() => validateSidebars({sidebar: [{type: 42}]}))
.toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": 42,
\\"undefined\\" [1]: -- missing --
"type": 42,
"undefined" [1]: -- missing --
}

[1] Unknown sidebar item type \\"42\\"."
[1] Unknown sidebar item type "42"."
`);
});
@ -53,20 +53,21 @@ describe('validateSidebars', () => {
},
],
}),
// eslint-disable-next-line jest/no-large-snapshots
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"category\\",
\\"items\\": [
"type": "category",
"items": [
{
\\"type\\": \\"doc\\",
\\"id\\": \\"doc1\\"
"type": "doc",
"id": "doc1"
}
],
\\"label\\" [1]: true
"label" [1]: true
}

[1] \\"label\\" must be a string"
[1] "label" must be a string"
`);
});
@ -82,14 +83,14 @@ describe('validateSidebars', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"link\\",
\\"href\\": \\"https://github.com\\",
\\"label\\" [1]: false
}

[1] \\"label\\" must be a string"
`);
"{
"type": "link",
"href": "https://github.com",
"label" [1]: false
}
[1] "label" must be a string"
`);
});
it('sidebars link wrong href', () => {
@ -104,16 +105,16 @@ describe('validateSidebars', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"link\\",
\\"label\\": \\"GitHub\\",
\\"href\\" [1]: [
\\"example.com\\"
]
}

[1] \\"href\\" contains an invalid value"
`);
"{
"type": "link",
"label": "GitHub",
"href" [1]: [
"example.com"
]
}
[1] "href" contains an invalid value"
`);
});
it('sidebars with unknown sidebar item type', () => {
@ -126,13 +127,13 @@ describe('validateSidebars', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"superman\\",
\\"undefined\\" [1]: -- missing --
}

[1] Unknown sidebar item type \\"superman\\"."
`);
"{
"type": "superman",
"undefined" [1]: -- missing --
}
[1] Unknown sidebar item type "superman"."
`);
});
it('sidebars category missing items', () => {
@ -152,12 +153,12 @@ describe('validateSidebars', () => {
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"category\\",
\\"label\\": \\"category\\",
\\"items\\" [1]: -- missing --
"type": "category",
"label": "category",
"items" [1]: -- missing --
}

[1] \\"items\\" is required"
[1] "items" is required"
`);
});
@ -180,13 +181,13 @@ describe('validateSidebars', () => {
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"category\\",
\\"label\\": \\"category\\",
\\"items\\": [],
\\"href\\" [1]: \\"https://google.com\\"
"type": "category",
"label": "category",
"items": [],
"href" [1]: "https://google.com"
}

[1] \\"href\\" is not allowed"
[1] "href" is not allowed"
`);
});
@ -217,15 +218,15 @@ describe('validateSidebars', () => {
],
}),
).toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"doc\\",
\\"id\\" [1]: [
\\"doc1\\"
]
}

[1] \\"id\\" must be a string"
`);
"{
"type": "doc",
"id" [1]: [
"doc1"
]
}
[1] "id" must be a string"
`);
});
it('html type requires a value', () => {
@ -240,11 +241,11 @@ describe('validateSidebars', () => {
expect(() => validateSidebars(sidebars))
.toThrowErrorMatchingInlineSnapshot(`
"{
\\"type\\": \\"html\\",
\\"value\\" [1]: -- missing --
"type": "html",
"value" [1]: -- missing --
}

[1] \\"value\\" is required"
[1] "value" is required"
`);
});
@ -269,9 +270,7 @@ describe('validateCategoryMetadataFile', () => {
it('throw for bad value', async () => {
expect(() =>
validateCategoryMetadataFile(42),
).toThrowErrorMatchingInlineSnapshot(
`"\\"value\\" must be of type object"`,
);
).toThrowErrorMatchingInlineSnapshot(`""value" must be of type object"`);
});
it('accept empty object', async () => {
@ -314,8 +313,6 @@ describe('validateCategoryMetadataFile', () => {
};
expect(() =>
validateCategoryMetadataFile(content),
).toThrowErrorMatchingInlineSnapshot(
`"\\"link.permalink\\" is not allowed"`,
);
).toThrowErrorMatchingInlineSnapshot(`""link.permalink" is not allowed"`);
});
});