Skip to content

Commit

Permalink
test(config): add temp test for defaultConfig
Browse files Browse the repository at this point in the history
Adds a temporary test to ensure that the new defaultConfig,
generated by Vite automatically from the `MermaidConfig` JSON Schema,
has the same values as the old defaultConfig
(taken from
https://github.com/mermaid-js/mermaid/blob/38013de7114966e8b1a83396703ef8158bb34466/packages/mermaid/src/defaultConfig.ts)

The only minor difference seems to be that:
  - `gitGraph` now has a default `useMaxWidth: false` option
    (previously used to be `undefined`),
  - `class` now has a `htmlLabels` value of `false` instead of `undefined`.
  • Loading branch information
aloisklink committed Jul 6, 2023
1 parent eb5d65f commit 063cb12
Show file tree
Hide file tree
Showing 2 changed files with 2,343 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/mermaid/src/config.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isObject from 'lodash-es/isObject.js';
import * as configApi from './config.js';

describe('when working with site config', function () {
Expand Down Expand Up @@ -53,4 +54,40 @@ describe('when working with site config', function () {
let config_4 = configApi.getConfig();
expect(config_4.foobar).toBeUndefined();
});

it('test new default config', async function () {
const { default: oldDefault } = await import('./oldDefaultConfig.js');
// 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)));

for (const key in newDefault) {
// 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

0 comments on commit 063cb12

Please sign in to comment.