mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-05 02:47:50 +02:00
test(utils, mdx-loader, core): improve coverage (#6303)
* test(utils, mdx-loader, core): improve coverage * windows... * fix
This commit is contained in:
parent
cf265c051e
commit
a79c23bc45
38 changed files with 841 additions and 219 deletions
|
@ -9,6 +9,7 @@ import {
|
|||
createExcerpt,
|
||||
parseMarkdownContentTitle,
|
||||
parseMarkdownString,
|
||||
parseMarkdownHeadingId,
|
||||
} from '../markdownParser';
|
||||
import dedent from 'dedent';
|
||||
|
||||
|
@ -827,4 +828,141 @@ describe('parseMarkdownString', () => {
|
|||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('should handle code blocks', () => {
|
||||
expect(
|
||||
parseMarkdownString(dedent`
|
||||
\`\`\`js
|
||||
code
|
||||
\`\`\`
|
||||
|
||||
Content
|
||||
`),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"content": "\`\`\`js
|
||||
code
|
||||
\`\`\`
|
||||
|
||||
Content",
|
||||
"contentTitle": undefined,
|
||||
"excerpt": "Content",
|
||||
"frontMatter": Object {},
|
||||
}
|
||||
`);
|
||||
expect(
|
||||
parseMarkdownString(dedent`
|
||||
\`\`\`\`js
|
||||
Foo
|
||||
\`\`\`diff
|
||||
code
|
||||
\`\`\`
|
||||
Bar
|
||||
\`\`\`\`
|
||||
|
||||
Content
|
||||
`),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"content": "\`\`\`\`js
|
||||
Foo
|
||||
\`\`\`diff
|
||||
code
|
||||
\`\`\`
|
||||
Bar
|
||||
\`\`\`\`
|
||||
|
||||
Content",
|
||||
"contentTitle": undefined,
|
||||
"excerpt": "Content",
|
||||
"frontMatter": Object {},
|
||||
}
|
||||
`);
|
||||
expect(
|
||||
parseMarkdownString(dedent`
|
||||
\`\`\`\`js
|
||||
Foo
|
||||
\`\`\`diff
|
||||
code
|
||||
\`\`\`\`
|
||||
|
||||
Content
|
||||
`),
|
||||
).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"content": "\`\`\`\`js
|
||||
Foo
|
||||
\`\`\`diff
|
||||
code
|
||||
\`\`\`\`
|
||||
|
||||
Content",
|
||||
"contentTitle": undefined,
|
||||
"excerpt": "Content",
|
||||
"frontMatter": Object {},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
test('throws for invalid front matter', () => {
|
||||
expect(() =>
|
||||
parseMarkdownString(dedent`
|
||||
---
|
||||
foo: f: a
|
||||
---
|
||||
`),
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 2, column 7:
|
||||
foo: f: a
|
||||
^"
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseMarkdownHeadingId', () => {
|
||||
test('can parse simple heading without id', () => {
|
||||
expect(parseMarkdownHeadingId('## Some heading')).toEqual({
|
||||
text: '## Some heading',
|
||||
id: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
test('can parse simple heading with id', () => {
|
||||
expect(parseMarkdownHeadingId('## Some heading {#custom-_id}')).toEqual({
|
||||
text: '## Some heading',
|
||||
id: 'custom-_id',
|
||||
});
|
||||
});
|
||||
|
||||
test('can parse heading not ending with the id', () => {
|
||||
expect(parseMarkdownHeadingId('## {#custom-_id} Some heading')).toEqual({
|
||||
text: '## {#custom-_id} Some heading',
|
||||
id: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
test('can parse heading with multiple id', () => {
|
||||
expect(parseMarkdownHeadingId('## Some heading {#id1} {#id2}')).toEqual({
|
||||
text: '## Some heading {#id1}',
|
||||
id: 'id2',
|
||||
});
|
||||
});
|
||||
|
||||
test('can parse heading with link and id', () => {
|
||||
expect(
|
||||
parseMarkdownHeadingId(
|
||||
'## Some heading [facebook](https://facebook.com) {#id}',
|
||||
),
|
||||
).toEqual({
|
||||
text: '## Some heading [facebook](https://facebook.com)',
|
||||
id: 'id',
|
||||
});
|
||||
});
|
||||
|
||||
test('can parse heading with only id', () => {
|
||||
expect(parseMarkdownHeadingId('## {#id}')).toEqual({
|
||||
text: '##',
|
||||
id: 'id',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue