From 51dbdb933c6e6f49294ca0766d695f417a683493 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 7 Sep 2022 11:56:31 +0530 Subject: [PATCH 1/2] Fix mermaidAPI mock Co-authored-by: Alois Klink --- src/mermaid.spec.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mermaid.spec.js b/src/mermaid.spec.js index c6014dfff..0e349dec5 100644 --- a/src/mermaid.spec.js +++ b/src/mermaid.spec.js @@ -1,15 +1,16 @@ -import mermaid from './mermaid'; -import { mermaidAPI } from './mermaidAPI'; -import flowDb from './diagrams/flowchart/flowDb'; +// mocks the mermaidAPI.render function (see `./__mocks__/mermaidAPI`) +jest.mock('./mermaidAPI'); +// jest.mock only works well with CJS, see https://github.com/facebook/jest/issues/9430 +const { default: mermaid } = require('./mermaid'); +const { mermaidAPI } = require('./mermaidAPI'); +const { default: flowDb } = require('./diagrams/flowchart/flowDb'); + import flowParser from './diagrams/flowchart/parser/flow'; import flowRenderer from './diagrams/flowchart/flowRenderer'; import Diagram from './Diagram'; const spyOn = jest.spyOn; -// mocks the mermaidAPI.render function (see `./__mocks__/mermaidAPI`) -jest.mock('./mermaidAPI'); - afterEach(() => { jest.restoreAllMocks(); }); @@ -54,6 +55,8 @@ describe('when using mermaid and ', function () { node.appendChild(document.createTextNode('graph TD;\na;')); mermaid.initThrowsErrors(undefined, node); + // mermaidAPI.render function has been mocked, since it doesn't yet work + // in Node.JS (only works in browser) expect(mermaidAPI.render).toHaveBeenCalled(); }); }); From a61c17c1a9b6d2809bdd05bbb5f17060c711d9c1 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 7 Sep 2022 12:02:59 +0530 Subject: [PATCH 2/2] Fix doc formatting --- docs/Setup.md | 31 +++++++++++++++++++++---------- package.json | 2 +- src/docs/Setup.md | 31 +++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/docs/Setup.md b/docs/Setup.md index 1f948ee01..2ef56e1d8 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -1407,6 +1407,15 @@ This sets the auto-wrap padding for the diagram (sides only) **Notes:** Default value: 0. +## parse + +### Parameters + +- `text` **[string][5]** +- `parseError` **[Function][6]?** + +Returns **[boolean][7]** + ## setSiteConfig ## setSiteConfig @@ -1424,7 +1433,7 @@ function _Default value: At default, will mirror Global Config_ - `conf` **MermaidConfig** The base currentConfig to use as siteConfig -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## getSiteConfig @@ -1436,7 +1445,7 @@ Returns **[object][5]** The siteConfig **Notes**: Returns **any** values in siteConfig. -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## setConfig @@ -1475,10 +1484,10 @@ $(function () { ### Parameters -- `id` **[string][6]** The id of the element to be rendered -- `text` **[string][6]** The graph definition -- `cb` **function (svgCode: [string][6], bindFunctions: function (element: [Element][7]): void): void** -- `container` **[Element][7]** Selector to element in which a div with the graph temporarily will be +- `id` **[string][5]** The id of the element to be rendered +- `text` **[string][5]** The graph definition +- `cb` **function (svgCode: [string][5], bindFunctions: function (element: [Element][9]): void): void** +- `container` **[Element][9]** Selector to element in which a div with the graph temporarily will be inserted. If one is provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. @@ -1517,7 +1526,7 @@ Pushes in a directive to the configuration ### Parameters -- `directive` **[object][5]** The directive to push in +- `directive` **[object][8]** The directive to push in ## reset @@ -1615,6 +1624,8 @@ Returns **void** [2]: Setup.md?id=render [3]: 8.6.0_docs.md [4]: #mermaidapi-configuration-defaults -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[7]: https://developer.mozilla.org/docs/Web/API/Element +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[9]: https://developer.mozilla.org/docs/Web/API/Element diff --git a/package.json b/package.json index b64b3bc6e..7cec9e40c 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "build": "yarn clean; concurrently \"yarn build:code\" \"yarn build:types\"", "docs:build": "ts-node-esm src/docs.mts", "docs:verify": "ts-node-esm src/docs.mts --verify", - "postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md; yarn docs:build", + "postbuild": "documentation build src/mermaidAPI.ts src/config.ts src/defaultConfig.ts --shallow -f md --markdown-toc false > src/docs/Setup.md; prettier --write src/docs/Setup.md; yarn docs:build", "release": "yarn build", "lint": "eslint --cache --ignore-path .gitignore .; prettier --check .", "lint:fix": "eslint --fix --ignore-path .gitignore .; prettier --write .", diff --git a/src/docs/Setup.md b/src/docs/Setup.md index a9d8e87e2..41e706825 100644 --- a/src/docs/Setup.md +++ b/src/docs/Setup.md @@ -1405,6 +1405,15 @@ This sets the auto-wrap padding for the diagram (sides only) **Notes:** Default value: 0. +## parse + +### Parameters + +- `text` **[string][5]** +- `parseError` **[Function][6]?** + +Returns **[boolean][7]** + ## setSiteConfig ## setSiteConfig @@ -1422,7 +1431,7 @@ function _Default value: At default, will mirror Global Config_ - `conf` **MermaidConfig** The base currentConfig to use as siteConfig -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## getSiteConfig @@ -1434,7 +1443,7 @@ Returns **[object][5]** The siteConfig **Notes**: Returns **any** values in siteConfig. -Returns **[object][5]** The siteConfig +Returns **[object][8]** The siteConfig ## setConfig @@ -1473,10 +1482,10 @@ $(function () { ### Parameters -- `id` **[string][6]** The id of the element to be rendered -- `text` **[string][6]** The graph definition -- `cb` **function (svgCode: [string][6], bindFunctions: function (element: [Element][7]): void): void** -- `container` **[Element][7]** Selector to element in which a div with the graph temporarily will be +- `id` **[string][5]** The id of the element to be rendered +- `text` **[string][5]** The graph definition +- `cb` **function (svgCode: [string][5], bindFunctions: function (element: [Element][9]): void): void** +- `container` **[Element][9]** Selector to element in which a div with the graph temporarily will be inserted. If one is provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. @@ -1515,7 +1524,7 @@ Pushes in a directive to the configuration ### Parameters -- `directive` **[object][5]** The directive to push in +- `directive` **[object][8]** The directive to push in ## reset @@ -1613,6 +1622,8 @@ Returns **void** [2]: Setup.md?id=render [3]: 8.6.0_docs.md [4]: #mermaidapi-configuration-defaults -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[7]: https://developer.mozilla.org/docs/Web/API/Element +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[9]: https://developer.mozilla.org/docs/Web/API/Element