mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 08:19:43 +02:00

The `node16` module resolution requires imports to use the `.js` file extension in type definitions. `@rollup/plugin-typescript` is needed to make this work with the Vite setup used by Mermaid. The module option for Mermaid internally is set to `nodenext`. This is needed to support `.json` imports. Note that setting `module` to `node16` or `nodenext` implies a matching `moduleResolution` value.
32 lines
876 B
TypeScript
32 lines
876 B
TypeScript
/**
|
|
* Mocks for `./mermaidAPI`.
|
|
*
|
|
* We can't easily use `vi.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`.
|
|
*/
|
|
import * as configApi from '../config.js';
|
|
import { vi } from 'vitest';
|
|
import { mermaidAPI as mAPI } from '../mermaidAPI.js';
|
|
|
|
// original version cannot be modified since it was frozen with `Object.freeze()`
|
|
export const mermaidAPI = {
|
|
render: vi.fn().mockResolvedValue({
|
|
svg: '<svg></svg>',
|
|
}),
|
|
parse: mAPI.parse,
|
|
parseDirective: vi.fn(),
|
|
initialize: vi.fn(),
|
|
getConfig: configApi.getConfig,
|
|
setConfig: configApi.setConfig,
|
|
getSiteConfig: configApi.getSiteConfig,
|
|
updateSiteConfig: configApi.updateSiteConfig,
|
|
reset: () => {
|
|
configApi.reset();
|
|
},
|
|
globalReset: () => {
|
|
configApi.reset(configApi.defaultConfig);
|
|
},
|
|
defaultConfig: configApi.defaultConfig,
|
|
};
|
|
|
|
export default mermaidAPI;
|