Enable eslint-plugin-jest, eslint-plugin-cypress and wider scan

This commit is contained in:
Matthieu MOREL
2021-11-18 19:17:00 +01:00
committed by MOREL Matthieu
parent 4089ee8786
commit d84be0d792
101 changed files with 2856 additions and 2830 deletions

View File

@@ -1,15 +1,14 @@
/* eslint-env jasmine */
import mermaidAPI from './mermaidAPI';
import { assignWithDepth } from './utils';
describe('when using mermaidAPI and ', function() {
describe('doing initialize ', function() {
beforeEach(function() {
describe('when using mermaidAPI and ', function () {
describe('doing initialize ', function () {
beforeEach(function () {
document.body.innerHTML = '';
mermaidAPI.globalReset();
});
it('should copy a literal into the configuration', function() {
it('should copy a literal into the configuration', function () {
const orgConfig = mermaidAPI.getConfig();
expect(orgConfig.testLiteral).toBe(undefined);
@@ -18,13 +17,13 @@ describe('when using mermaidAPI and ', function() {
expect(config.testLiteral).toBe(true);
});
it('should copy a an object into the configuration', function() {
it('should copy a an object into the configuration', function () {
const orgConfig = mermaidAPI.getConfig();
expect(orgConfig.testObject).toBe(undefined);
const object = {
test1: 1,
test2: false
test2: false,
};
mermaidAPI.initialize({ testObject: object });
@@ -38,13 +37,13 @@ describe('when using mermaidAPI and ', function() {
expect(config.testObject.test2).toBe(false);
expect(config.testObject.test3).toBe(true);
});
it('should reset mermaid config to global defaults', function() {
it('should reset mermaid config to global defaults', function () {
let config = {
logLevel: 0,
securityLevel: 'loose'
securityLevel: 'loose',
};
mermaidAPI.initialize(config);
mermaidAPI.setConfig({securityLevel:'strict', logLevel: 1});
mermaidAPI.setConfig({ securityLevel: 'strict', logLevel: 1 });
expect(mermaidAPI.getConfig().logLevel).toBe(1);
expect(mermaidAPI.getConfig().securityLevel).toBe('strict');
mermaidAPI.globalReset();
@@ -52,68 +51,73 @@ describe('when using mermaidAPI and ', function() {
expect(mermaidAPI.getConfig().securityLevel).toBe('loose');
});
it('should prevent changes to site defaults (sneaky)', function() {
it('should prevent changes to site defaults (sneaky)', function () {
let config = {
logLevel: 0
logLevel: 0,
};
mermaidAPI.initialize(config);
const siteConfig = mermaidAPI.getSiteConfig();
expect(mermaidAPI.getConfig().logLevel).toBe(0);
config.secure = {
toString: function() {
toString: function () {
mermaidAPI.initialize({ securityLevel: 'loose' });
}
},
};
mermaidAPI.reinitialize(config);
expect(mermaidAPI.getConfig().secure).toEqual(mermaidAPI.getSiteConfig().secure);
expect(mermaidAPI.getConfig().securityLevel).toBe('strict');
mermaidAPI.reset();
expect(mermaidAPI.getSiteConfig()).toEqual(siteConfig)
expect(mermaidAPI.getSiteConfig()).toEqual(siteConfig);
expect(mermaidAPI.getConfig()).toEqual(siteConfig);
});
it('should prevent clobbering global defaults (direct)', function() {
it('should prevent clobbering global defaults (direct)', function () {
let config = assignWithDepth({}, mermaidAPI.defaultConfig);
assignWithDepth(config, { logLevel: 0 });
let error = { message: '' };
try {
mermaidAPI['defaultConfig'] = config;
} catch(e) {
} catch (e) {
error = e;
}
expect(error.message).toBe('Cannot assign to read only property \'defaultConfig\' of object \'#<Object>\'');
expect(error.message).toBe(
"Cannot assign to read only property 'defaultConfig' of object '#<Object>'"
);
expect(mermaidAPI.defaultConfig['logLevel']).toBe(5);
});
it('should prevent changes to global defaults (direct)', function() {
it('should prevent changes to global defaults (direct)', function () {
let error = { message: '' };
try {
mermaidAPI.defaultConfig['logLevel'] = 0;
} catch(e) {
} catch (e) {
error = e;
}
expect(error.message).toBe('Cannot assign to read only property \'logLevel\' of object \'#<Object>\'');
expect(error.message).toBe(
"Cannot assign to read only property 'logLevel' of object '#<Object>'"
);
expect(mermaidAPI.defaultConfig['logLevel']).toBe(5);
});
it('should prevent sneaky changes to global defaults (assignWithDepth)', function() {
it('should prevent sneaky changes to global defaults (assignWithDepth)', function () {
let config = {
logLevel: 0
logLevel: 0,
};
let error = { message: '' };
try {
assignWithDepth(mermaidAPI.defaultConfig, config);
} catch(e) {
} catch (e) {
error = e;
}
expect(error.message).toBe('Cannot assign to read only property \'logLevel\' of object \'#<Object>\'');
expect(error.message).toBe(
"Cannot assign to read only property 'logLevel' of object '#<Object>'"
);
expect(mermaidAPI.defaultConfig['logLevel']).toBe(5);
});
});
describe('checking validity of input ', function() {
it('it should throw for an invalid definiton', function() {
describe('checking validity of input ', function () {
it('it should throw for an invalid definiton', function () {
expect(() => mermaidAPI.parse('this is not a mermaid diagram definition')).toThrow();
});
it('it should not throw for a valid definiton', function() {
it('it should not throw for a valid definiton', function () {
expect(() => mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).not.toThrow();
});
});