mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
fix: unitTests after tripleParsing removal
This commit is contained in:
parent
10d5b5d1d6
commit
95efc1786f
@ -4,8 +4,9 @@ import { getDiagram, registerDiagram } from './diagram-api/diagramAPI.js';
|
||||
import { detectType, getDiagramLoader } from './diagram-api/detectType.js';
|
||||
import { extractFrontMatter } from './diagram-api/frontmatter.js';
|
||||
import { UnknownDiagramError } from './errors.js';
|
||||
import { DetailedError } from './utils.js';
|
||||
import { cleanupComments } from './diagram-api/comments.js';
|
||||
import type { DetailedError } from './utils.js';
|
||||
import type { MermaidConfig } from './config.type.js';
|
||||
|
||||
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
|
||||
|
||||
@ -18,6 +19,7 @@ export class Diagram {
|
||||
parser;
|
||||
renderer;
|
||||
db;
|
||||
private init?: (config: MermaidConfig) => void;
|
||||
private detectError?: UnknownDiagramError;
|
||||
constructor(public text: string) {
|
||||
this.text += '\n';
|
||||
@ -48,11 +50,7 @@ export class Diagram {
|
||||
originalParse(cleanupComments(extractFrontMatter(text, this.db)));
|
||||
|
||||
this.parser.parser.yy = this.db;
|
||||
this.db.clear?.();
|
||||
if (diagram.init) {
|
||||
diagram.init(cnf);
|
||||
log.info('Initialized diagram ' + this.type, cnf);
|
||||
}
|
||||
this.init = diagram.init;
|
||||
this.parse();
|
||||
}
|
||||
|
||||
@ -60,6 +58,12 @@ export class Diagram {
|
||||
if (this.detectError) {
|
||||
throw this.detectError;
|
||||
}
|
||||
this.db.clear?.();
|
||||
if (this.init) {
|
||||
const config = configApi.getConfig();
|
||||
this.init(config);
|
||||
log.info('Initialized diagram ' + this.type, config);
|
||||
}
|
||||
this.parser.parse(this.text);
|
||||
}
|
||||
|
||||
|
@ -173,13 +173,12 @@ describe('more than one sequence diagram', () => {
|
||||
describe('when parsing a sequenceDiagram', function () {
|
||||
beforeEach(function () {
|
||||
// diagram.db = sequenceDb;
|
||||
// diagram.db.clear();
|
||||
//
|
||||
diagram = new Diagram(`
|
||||
sequenceDiagram
|
||||
Alice->Bob:Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!`);
|
||||
diagram.db.clear();
|
||||
});
|
||||
it('should handle a sequenceDiagram definition', async function () {
|
||||
const str = `
|
||||
@ -1482,8 +1481,6 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
||||
let conf;
|
||||
beforeEach(function () {
|
||||
mermaidAPI.reset();
|
||||
// diagram.db = sequenceDb;
|
||||
// diagram.db.clear();
|
||||
diagram.renderer.bounds.init();
|
||||
conf = diagram.db.getConfig();
|
||||
});
|
||||
@ -1635,7 +1632,6 @@ sequenceDiagram
|
||||
Alice->Bob:Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!`);
|
||||
diagram.db.clear();
|
||||
});
|
||||
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
||||
it(`
|
||||
@ -2009,8 +2005,6 @@ describe('when rendering a sequenceDiagram with actor mirror activated', () => {
|
||||
let conf;
|
||||
beforeEach(function () {
|
||||
mermaidAPI.reset();
|
||||
// diagram.db = sequenceDb;
|
||||
diagram.db.clear();
|
||||
conf = diagram.db.getConfig();
|
||||
diagram.renderer.bounds.init();
|
||||
});
|
||||
@ -2052,12 +2046,9 @@ describe('when rendering a sequenceDiagram with directives', () => {
|
||||
mermaidAPI.initialize({ sequence: conf });
|
||||
});
|
||||
|
||||
let conf;
|
||||
beforeEach(function () {
|
||||
mermaidAPI.reset();
|
||||
// diagram.db = sequenceDb;
|
||||
diagram.db.clear();
|
||||
conf = diagram.db.getConfig();
|
||||
diagram.renderer.bounds.init();
|
||||
});
|
||||
|
||||
@ -2069,10 +2060,7 @@ sequenceDiagram
|
||||
participant Alice
|
||||
`;
|
||||
diagram = new Diagram(str);
|
||||
|
||||
diagram.renderer.bounds.init();
|
||||
await mermaidAPI.parse(str);
|
||||
|
||||
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
||||
|
||||
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
||||
@ -2093,7 +2081,7 @@ sequenceDiagram
|
||||
participant Alice
|
||||
`;
|
||||
|
||||
diagram.parse(str);
|
||||
diagram = new Diagram(str);
|
||||
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
||||
|
||||
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
||||
@ -2114,7 +2102,7 @@ Alice->Bob:Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!`;
|
||||
|
||||
await mermaidAPI.parse(str1);
|
||||
diagram = new Diagram(str1);
|
||||
diagram.renderer.draw(str1, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers
|
||||
expect(diagram.db.showSequenceNumbers()).toBe(true);
|
||||
|
||||
@ -2124,7 +2112,7 @@ Alice->Bob:Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!`;
|
||||
|
||||
await mermaidAPI.parse(str2);
|
||||
diagram = new Diagram(str2);
|
||||
diagram.renderer.draw(str2, 'tst', '1.2.3', diagram);
|
||||
expect(diagram.db.showSequenceNumbers()).toBe(false);
|
||||
});
|
||||
|
@ -108,8 +108,8 @@ export interface RenderResult {
|
||||
async function parse(text: string, parseOptions?: ParseOptions): Promise<boolean> {
|
||||
addDiagrams();
|
||||
try {
|
||||
const diagram = await getDiagramFromText(text);
|
||||
diagram.parse();
|
||||
await getDiagramFromText(text);
|
||||
// diagram.parse();
|
||||
} catch (error) {
|
||||
if (parseOptions?.suppressErrors) {
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user