test: fix 'new default config' test
This test was accidentally removed by a bad merge commit, see29291c89
(Merge branch 'develop' into pr/aloisklink/4112, 2023-07-06). This test checks whether the default config defined in the `config.schema.yaml` file matches the old default config defined in `oldDefaultConfig.ts`. Fixes:29291c8901
This commit is contained in:
parent
194ef202ac
commit
2b53e02153
|
@ -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<MermaidConfig>;
|
||||
};
|
||||
// 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]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue