test: Fix parse tests

This commit is contained in:
Sidharth Vinod
2024-09-10 17:08:15 +05:30
parent 900c8a4209
commit d0caa2b3e0

View File

@@ -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,23 +695,29 @@ 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": {
@@ -720,35 +726,41 @@ graph TD;A--x|text including URL space|B;`)
}, },
"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": {
@@ -757,17 +769,17 @@ graph TD;A--x|text including URL space|B;`)
}, },
"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",
} }
`); `);
}); });