Skip to content

Commit

Permalink
fix(Linter): correctly parse C7 XML
Browse files Browse the repository at this point in the history
this requires a new configuration option `type = platform` to be set

related to camunda/camunda-modeler#3853
  • Loading branch information
marstamm committed Sep 22, 2023
1 parent c3af885 commit e795474
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const modeler = new Modeler({

// configure to be used with desktop or web modeler
const linter = new Linter({
modeler: 'web'
modeler: 'web',
type: 'cloud' // cloud or platform diagrams, defaults to `cloud`
});

// lint by passing definitions
Expand Down
21 changes: 14 additions & 7 deletions lib/Linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { resolver as RulesResolver } from './compiled-config';

import modelerModdle from 'modeler-moddle/resources/modeler.json';
import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe.json';
import camundaModdle from 'camunda-bpmn-moddle/resources/camunda.json';

import { getErrorMessage } from './utils/error-messages';
import { getEntryIds } from './utils/properties-panel';
Expand All @@ -19,18 +20,24 @@ import { toSemverMinor } from './utils/version';

import { getDocumentationUrl } from './utils/documentation';

const moddle = new BpmnModdle({
modeler: modelerModdle,
zeebe: zeebeModdle
});

export class Linter {
constructor(options = {}) {
const {
modeler = 'desktop',
plugins = []
plugins = [],
type = 'cloud'
} = options;

this._moddle = new BpmnModdle({
modeler: modelerModdle,

// Zeebe and Camunda moddle extensions can't be used together
// cf. https://github.com/camunda/camunda-modeler/issues/3853#issuecomment-1731145100
...(type === 'cloud' ?
{ zeebe: zeebeModdle } :
{ camunda: camundaModdle })
});

this._modeler = modeler;
this._plugins = plugins;
}
Expand All @@ -39,7 +46,7 @@ export class Linter {
let rootElement;

if (isString(contents)) {
({ rootElement } = await moddle.fromXML(contents));
({ rootElement } = await this._moddle.fromXML(contents));
} else {
rootElement = contents;
}
Expand Down
94 changes: 75 additions & 19 deletions test/spec/Linter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ describe('Linter', function() {

describe('camunda-cloud', function() {

beforeEach(function() {
linter = new Linter({ type: 'cloud' });
});

const versions = [
[ '1.0', camundaCloud10XML, camundaCloud10ErrorsXML ],
[ '1.1', camundaCloud11XML, camundaCloud11ErrorsXML ],
Expand All @@ -165,7 +169,7 @@ describe('Linter', function() {

describe(`Camunda Cloud ${ version }`, function() {

describe('no errors', function() {
describe('from moddle', function() {

it('should not have errors', async function() {

Expand All @@ -179,10 +183,6 @@ describe('Linter', function() {
expect(reports).to.be.empty;
});

});


describe('errors', function() {

it('should have errors', async function() {

Expand All @@ -198,6 +198,30 @@ describe('Linter', function() {

});


describe('from XML', function() {

it('should not have errors', async function() {

// when
const reports = await linter.lint(xml);

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {

// when
const reports = await linter.lint(errorsXML);

// then
expect(reports).not.to.be.empty;
});

});

});

});
Expand All @@ -207,6 +231,10 @@ describe('Linter', function() {

describe('camunda-platform', function() {

beforeEach(function() {
linter = new Linter({ type: 'platform' });
});

const versions = [
[ '7.19', camundaPlatform719XML, camundaPlatform719ErrorsXML ],
[ '7.20', camundaPlatform720XML, camundaPlatform720ErrorsXML ]
Expand All @@ -229,29 +257,57 @@ describe('Linter', function() {

describe(`Camunda Platform ${ version }`, function() {

it('should not have errors', async function() {
describe('from moddle', function() {

it('should not have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(xml);

// when
const reports = await linter.lint(root);

// then
expect(reports).to.be.empty;
});


// given
const { root } = await createModdleCamundaPlatform(xml);
it('should have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(errorsXML);

// when
const reports = await linter.lint(root);

// when
const reports = await linter.lint(root);
// then
expect(reports).not.to.be.empty;
});

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {
describe('from xml', function() {

it('should not have errors', async function() {

// when
const reports = await linter.lint(xml);

// then
expect(reports).to.be.empty;
});


it('should have errors', async function() {

// given
const { root } = await createModdleCamundaPlatform(errorsXML);
// when
const reports = await linter.lint(errorsXML);

// when
const reports = await linter.lint(root);
// then
expect(reports).not.to.be.empty;
});

// then
expect(reports).not.to.be.empty;
});

});
Expand Down
10 changes: 7 additions & 3 deletions test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ describe('Linting', function() {
]
});

const lint = () => {
const definitions = bpmnjs.getDefinitions();
const lint = async () => {

linter.lint(definitions).then(reports => {
// const definitions = bpmnjs.getDefinitions();
const xml = await bpmnjs.saveXML();

console.clear();
window.__log = true;
linter.lint(xml.xml).then(reports => {
linting.setErrors(reports);

const container = panel.querySelector('.errorContainer');
Expand Down

0 comments on commit e795474

Please sign in to comment.