diff --git a/packages/mermaid/src/config.spec.ts b/packages/mermaid/src/config.spec.ts index 457cb8244..6a9eb204c 100644 --- a/packages/mermaid/src/config.spec.ts +++ b/packages/mermaid/src/config.spec.ts @@ -1,4 +1,6 @@ import * as configApi from './config.js'; +import isObject from 'lodash-es/isObject.js'; +import type { MermaidConfig } from './config.type.js'; describe('when working with site config', function () { beforeEach(() => { @@ -69,4 +71,43 @@ describe('when working with site config', function () { const config_4 = configApi.getConfig(); expect(config_4.altFontFamily).toBeUndefined(); }); + + it('test new default config', async function () { + const { default: oldDefault } = (await import('./oldDefaultConfig.js')) as { + default: Required; + }; + // gitGraph used to not have this option (aka it was `undefined`) + oldDefault.gitGraph.useMaxWidth = false; + + // class diagrams used to not have these options set (aka they were `undefined`) + oldDefault.class.htmlLabels = false; + + const { default: newDefault } = await import('./defaultConfig.js'); + + // check subsets of the objects, to improve vitest error messages + // we can't just use `expect(newDefault).to.deep.equal(oldDefault);` + // because the functions in the config won't be the same + expect(new Set(Object.keys(newDefault))).to.deep.equal(new Set(Object.keys(oldDefault))); + + // @ts-ignore: Expect that all the keys in newDefault are valid MermaidConfig keys + Object.keys(newDefault).forEach((key: keyof MermaidConfig) => { + // recurse through object, since we want to treat functions differently + if (!Array.isArray(newDefault[key]) && isObject(newDefault[key])) { + expect(new Set(Object.keys(newDefault[key]))).to.deep.equal( + new Set(Object.keys(oldDefault[key])) + ); + for (const key2 in newDefault[key]) { + if (typeof newDefault[key][key2] === 'function') { + expect(newDefault[key][key2].toString()).to.deep.equal( + oldDefault[key][key2].toString() + ); + } else { + expect(newDefault[key]).to.have.deep.property(key2, oldDefault[key][key2]); + } + } + } else { + expect(newDefault[key]).to.deep.equal(oldDefault[key]); + } + }); + }); });