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

@ -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"`);
});
});