mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00
test: Fix parse tests
This commit is contained in:
@@ -35,7 +35,7 @@ vi.mock('./diagrams/sequence/sequenceRenderer.js');
|
|||||||
|
|
||||||
import assignWithDepth from './assignWithDepth.js';
|
import assignWithDepth from './assignWithDepth.js';
|
||||||
import type { MermaidConfig } from './config.type.js';
|
import type { MermaidConfig } from './config.type.js';
|
||||||
import mermaid from './mermaid.js';
|
import mermaid, { type ParseResult } from './mermaid.js';
|
||||||
import mermaidAPI, {
|
import mermaidAPI, {
|
||||||
appendDivSvgG,
|
appendDivSvgG,
|
||||||
cleanUpSvgCode,
|
cleanUpSvgCode,
|
||||||
@@ -695,81 +695,93 @@ describe('mermaidAPI', () => {
|
|||||||
).resolves.toBe(false);
|
).resolves.toBe(false);
|
||||||
});
|
});
|
||||||
it('resolves for valid definition', async () => {
|
it('resolves for valid definition', async () => {
|
||||||
await expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).resolves
|
await expect(
|
||||||
.toMatchInlineSnapshot(`
|
mermaidAPI
|
||||||
|
.parse('graph TD;A--x|text including URL space|B;')
|
||||||
|
.then((p) => ({ config: p.config }))
|
||||||
|
).resolves.toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"config": {},
|
"config": {},
|
||||||
"diagramType": "flowchart-v2",
|
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
it('returns config when defined in frontmatter', async () => {
|
it('returns config when defined in frontmatter', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mermaidAPI.parse(`---
|
mermaidAPI
|
||||||
|
.parse(
|
||||||
|
`---
|
||||||
config:
|
config:
|
||||||
theme: base
|
theme: base
|
||||||
flowchart:
|
flowchart:
|
||||||
htmlLabels: true
|
htmlLabels: true
|
||||||
---
|
---
|
||||||
graph TD;A--x|text including URL space|B;`)
|
graph TD;A--x|text including URL space|B;`
|
||||||
|
)
|
||||||
|
.then((p) => ({ config: p.config }))
|
||||||
).resolves.toMatchInlineSnapshot(`
|
).resolves.toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"flowchart": {
|
"flowchart": {
|
||||||
"htmlLabels": true,
|
"htmlLabels": true,
|
||||||
},
|
},
|
||||||
"theme": "base",
|
"theme": "base",
|
||||||
},
|
},
|
||||||
"diagramType": "flowchart-v2",
|
}
|
||||||
}
|
`);
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns config when defined in directive', async () => {
|
it('returns config when defined in directive', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mermaidAPI.parse(`%%{init: { 'theme': 'base' } }%%
|
mermaidAPI
|
||||||
graph TD;A--x|text including URL space|B;`)
|
.parse(
|
||||||
|
`%%{init: { 'theme': 'base' } }%%
|
||||||
|
graph TD;A--x|text including URL space|B;`
|
||||||
|
)
|
||||||
|
.then((p) => ({ config: p.config }))
|
||||||
).resolves.toMatchInlineSnapshot(`
|
).resolves.toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"theme": "base",
|
"theme": "base",
|
||||||
},
|
},
|
||||||
"diagramType": "flowchart-v2",
|
}
|
||||||
}
|
`);
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns merged config when defined in frontmatter and directive', async () => {
|
it('returns merged config when defined in frontmatter and directive', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mermaidAPI.parse(`---
|
mermaidAPI
|
||||||
|
.parse(
|
||||||
|
`---
|
||||||
config:
|
config:
|
||||||
theme: forest
|
theme: forest
|
||||||
flowchart:
|
flowchart:
|
||||||
htmlLabels: true
|
htmlLabels: true
|
||||||
---
|
---
|
||||||
%%{init: { 'theme': 'base' } }%%
|
%%{init: { 'theme': 'base' } }%%
|
||||||
graph TD;A--x|text including URL space|B;`)
|
graph TD;A--x|text including URL space|B;`
|
||||||
|
)
|
||||||
|
.then((p) => ({ config: p.config }))
|
||||||
).resolves.toMatchInlineSnapshot(`
|
).resolves.toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"flowchart": {
|
"flowchart": {
|
||||||
"htmlLabels": true,
|
"htmlLabels": true,
|
||||||
},
|
},
|
||||||
"theme": "base",
|
"theme": "base",
|
||||||
},
|
},
|
||||||
"diagramType": "flowchart-v2",
|
}
|
||||||
}
|
`);
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
it('returns true for valid definition with silent option', async () => {
|
it('returns true for valid definition with silent option', async () => {
|
||||||
await expect(
|
await expect(
|
||||||
mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
|
mermaidAPI
|
||||||
|
.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
|
||||||
|
.then((p) => ({ config: (p as ParseResult).config }))
|
||||||
).resolves.toMatchInlineSnapshot(`
|
).resolves.toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"config": {},
|
"config": {},
|
||||||
"diagramType": "flowchart-v2",
|
}
|
||||||
}
|
`);
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user