diff --git a/karma.config.js b/karma.config.cjs similarity index 100% rename from karma.config.js rename to karma.config.cjs diff --git a/package.json b/package.json index fd35b249..e4f81e78 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,14 @@ ], "exports": { ".": { - "import": "./dist/index.esm.js", - "require": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" }, "./core": { - "import": "./dist/core.esm.js", - "require": "./dist/core.js" + "import": "./dist/core.js", + "require": "./dist/core.cjs" }, "./dist/assets/*.css": "./dist/assets/*.css", - "./dist/*.js": "./dist/*.js", "./package.json": "./package.json" }, "scripts": { @@ -24,10 +23,10 @@ "build": "run-p bundle", "bundle": "rollup -c", "bundle:watch": "rollup -c -w", - "lint": "eslint .", + "lint": "eslint . --ext js,cjs,mjs", "dev": "npm test -- --auto-watch --no-single-run", - "test": "karma start karma.config.js", - "test:build": "mocha --reporter=spec --recursive test/distro/*.spec.js", + "test": "karma start karma.config.cjs", + "test:build": "mocha --reporter=spec --recursive test/distro/*.spec.c?js", "start": "cross-env SINGLE_START=cloud-templates npm run dev", "start:templates": "cross-env SINGLE_START=templates npm run dev", "prepare": "run-s bundle" @@ -46,9 +45,9 @@ "properties-panel", "element-templates" ], - "main": "dist/index.js", - "module": "dist/index.esm.js", - "umd:main": "dist/bpmn-js-element-templates.umd.js", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", "author": { "name": "Nico Rehwaldt", "url": "https://github.com/nikku" diff --git a/rollup.config.mjs b/rollup.config.mjs index b7767aed..df420c17 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -15,18 +15,6 @@ const nonbundledDependencies = Object.keys({ ...pkg.dependencies, ...pkg.peerDep const nonExternalDependencies = [ 'preact-markup' ]; export default [ - { - input: 'src/index.js', - output: [ - { - sourcemap: true, - format: 'umd', - file: pkg['umd:main'], - name: 'BpmnJSElementTemplates' - } - ], - plugins: pgl() - }, { input: 'src/index.js', output: [ diff --git a/test/.eslintrc b/test/.eslintrc index 277157d6..dae5f765 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -5,5 +5,8 @@ ], "globals": { "sinon": true + }, + "parserOptions": { + "ecmaVersion": 2020 } } \ No newline at end of file diff --git a/test/TestHelper.js b/test/TestHelper.js index 1209f77b..41ce433b 100644 --- a/test/TestHelper.js +++ b/test/TestHelper.js @@ -12,8 +12,6 @@ import { insertCSS } from 'bpmn-js/test/helper'; -import semver from 'semver'; - import fileDrop from 'file-drops'; import download from 'downloadjs'; @@ -23,25 +21,18 @@ import Modeler from 'bpmn-js/lib/Modeler'; import BPMNModdle from 'bpmn-moddle'; import zeebeModdle from 'zeebe-bpmn-moddle/resources/zeebe'; -let PROPERTIES_PANEL_CONTAINER; +import propertiesPanelCSS from '@bpmn-io/properties-panel/dist/assets/properties-panel.css'; -global.chai.use(function(chai, utils) { +import elementTemplatesCSS from '../assets/element-templates.css'; +import elementTemplateChooserCSS from '@bpmn-io/element-template-chooser/dist/element-template-chooser.css'; +import lintingCSS from '@camunda/linting/assets/linting.css'; - utils.addMethod(chai.Assertion.prototype, 'jsonEqual', function(comparison) { +import testCSS from './test.css'; - var actual = JSON.stringify(this._obj); - var expected = JSON.stringify(comparison); +import diagramCSS from 'bpmn-js/dist/assets/diagram-js.css'; +import bpmnJsCSS from 'bpmn-js/dist/assets/bpmn-js.css'; +import bpmnFontCSS from 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css'; - this.assert( - actual == expected, - 'expected #{this} to deep equal #{act}', - 'expected #{this} not to deep equal #{act}', - comparison, // expected - this._obj, // actual - true // show diff - ); - }); -}); export * from 'bpmn-js/test/helper'; @@ -50,6 +41,8 @@ export { createEvent } from 'bpmn-js/test/util/MockEvents'; +let PROPERTIES_PANEL_CONTAINER; + export function bootstrapPropertiesPanel(diagram, options, locals) { return async function() { const container = TestContainer.get(this); @@ -92,96 +85,25 @@ export function clickInput(input) { } export function insertCoreStyles() { - insertCSS( - 'properties-panel.css', - require('@bpmn-io/properties-panel/dist/assets/properties-panel.css').default - ); - - insertCSS( - 'element-templates.css', - require('../assets/element-templates.css').default - ); - - insertCSS( - 'test.css', - require('./test.css').default - ); - - insertCSS( - 'element-template-chooser.css', - require('@bpmn-io/element-template-chooser/dist/element-template-chooser.css').default - ); - - insertCSS('linting.css', - require('@camunda/linting/assets/linting.css').default - ); + insertCSS('properties-panel.css', propertiesPanelCSS); + insertCSS('element-templates.css', elementTemplatesCSS); + insertCSS('element-template-chooser.css', elementTemplateChooserCSS); + insertCSS('linting.css', lintingCSS); + insertCSS('test.css', testCSS); } export function insertBpmnStyles() { - insertCSS( - 'diagram.css', - require('bpmn-js/dist/assets/diagram-js.css').default - ); - - // @barmac: this fails before bpmn-js@9 - if (bpmnJsSatisfies('>=9')) { - insertCSS( - 'bpmn-js.css', - require('bpmn-js/dist/assets/bpmn-js.css').default - ); - } + insertCSS('diagram.css', diagramCSS); - insertCSS( - 'bpmn-font.css', - require('bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css').default - ); + insertCSS('bpmn-js.css', bpmnJsCSS); + insertCSS('bpmn-font.css', bpmnFontCSS); } export function bootstrapModeler(diagram, options, locals) { return bootstrapBpmnJS(Modeler, diagram, options, locals); } -/** - * Execute test only if currently installed bpmn-js is of given version. - * - * @param {string} versionRange - * @param {boolean} only - */ -export function withBpmnJs(versionRange, only = false) { - if (bpmnJsSatisfies(versionRange)) { - return only ? it.only : it; - } else { - return it.skip; - } -} - -function bpmnJsSatisfies(versionRange) { - const bpmnJsVersion = require('bpmn-js/package.json').version; - - return semver.satisfies(bpmnJsVersion, versionRange, { includePrerelease: true }); -} - -/** - * Execute test only if currently installed @bpmn-io/properties-panel is of given version. - * - * @param {string} versionRange - * @param {boolean} only - */ -export function withPropertiesPanel(versionRange, only = false) { - if (propertiesPanelSatisfies(versionRange)) { - return only ? it.only : it; - } else { - return it.skip; - } -} - -function propertiesPanelSatisfies(versionRange) { - const version = require('@bpmn-io/properties-panel/package.json').version; - - return semver.satisfies(version, versionRange, { includePrerelease: true }); -} - export async function setEditorValue(editor, value) { await act(() => { editor.textContent = value; @@ -283,4 +205,24 @@ export function createProcess(bpmn = '', bpmndi = '') { ${ bpmndi } `); -} \ No newline at end of file +} + +// additional chai helpers ////////////// + +global.chai.use(function(chai, utils) { + + utils.addMethod(chai.Assertion.prototype, 'jsonEqual', function(comparison) { + + var actual = JSON.stringify(this._obj); + var expected = JSON.stringify(comparison); + + this.assert( + actual == expected, + 'expected #{this} to deep equal #{act}', + 'expected #{this} not to deep equal #{act}', + comparison, // expected + this._obj, // actual + true // show diff + ); + }); +}); \ No newline at end of file diff --git a/test/coverageBundle.js b/test/coverageBundle.js index 31e2e4b9..42b41feb 100644 --- a/test/coverageBundle.js +++ b/test/coverageBundle.js @@ -1,7 +1,13 @@ -const allTests = require.context('./spec', true, /.spec\.js$/); +const allTests = import.meta.webpackContext('./spec', { + recursive: true, + regExp: /.spec\.js$/ +}); allTests.keys().forEach(allTests); -const allSources = require.context('../src', true, /.*\.js$/); +const allSources = import.meta.webpackContext('../src', { + recursive: true, + regExp: /.*\.js$/ +}); allSources.keys().forEach(allSources); \ No newline at end of file diff --git a/test/distro/distro.spec.cjs b/test/distro/distro.spec.cjs new file mode 100644 index 00000000..f481593e --- /dev/null +++ b/test/distro/distro.spec.cjs @@ -0,0 +1,37 @@ +const { + expect +} = require('chai'); + + +describe('exports', function() { + + it('should expose CJS bundle', function() { + + expect(() => require.resolve('bpmn-js-element-templates')).not.to.throw; + expect(() => require.resolve('bpmn-js-elemenet-templates/core')).not.to.throw; + + }); + +}); + + +describe('assets', function() { + + const EXPORTS = [ + 'bpmn-js-element-templates', + 'bpmn-js-element-templates/core', + 'bpmn-js-element-templates/dist/assets/element-templates.css', + 'bpmn-js-element-templates/package.json' + ]; + + EXPORTS.forEach(function(asset) { + + it(`should expose <${asset}>`, function() { + + expect(() => require.resolve(asset)).not.to.throw(); + + }); + + }); + +}); \ No newline at end of file diff --git a/test/distro/distro.spec.js b/test/distro/distro.spec.js deleted file mode 100644 index c39a0823..00000000 --- a/test/distro/distro.spec.js +++ /dev/null @@ -1,46 +0,0 @@ -const { - expect -} = require('chai'); - -const fs = require('fs'), - path = require('path'); - -const DIST_DIR = path.join(__dirname, '../../dist'); - -const EXPORTS = [ - 'bpmn-js-element-templates', - 'bpmn-js-element-templates/core', - 'bpmn-js-element-templates/dist/assets/element-templates.css', - 'bpmn-js-element-templates/dist/bpmn-js-element-templates.umd.js', - 'bpmn-js-element-templates/package.json' -]; - -describe('modules', function() { - - it('should expose CJS bundle', verifyExists('index.js')); - -}); - - -describe('assets', function() { - - EXPORTS.forEach(function(asset) { - - it(`should expose "${asset}"`, function() { - - expect(() => require.resolve(asset)).not.to.throw(); - }); - - }); -}); - -function verifyExists(relativePath) { - return function() { - - // given - const filePath = path.join(DIST_DIR, relativePath); - - // then - expect(fs.existsSync(filePath), `file ${relativePath} does not exist`).to.be.true; - }; -} diff --git a/test/spec/Example.spec.js b/test/spec/Example.spec.js index 3d0ac951..f30cfe50 100644 --- a/test/spec/Example.spec.js +++ b/test/spec/Example.spec.js @@ -170,12 +170,19 @@ describe('', function() { (singleStart === 'cloud-templates' ? it.only : it)('should import simple process (cloud-templates)', async function() { // given - const diagramXml = require('test/spec/cloud-element-templates/fixtures/complex.bpmn').default; + const diagramXml = (await import('test/spec/cloud-element-templates/fixtures/complex.bpmn')).default; - const elementTemplateContext = require.context('test/spec/cloud-element-templates/fixtures', false, /\.json$/); + const elementTemplateContext = import.meta.webpackContext('test/spec/cloud-element-templates/fixtures', { + recursive: false, + regExp: /\.json$/ + }); + + console.log(elementTemplateContext.keys()); const elementTemplates = elementTemplateContext.keys().map(key => elementTemplateContext(key)).flat(); + console.log(elementTemplates); + // when const result = await createModeler( diagramXml, @@ -273,9 +280,12 @@ describe('', function() { (singleStart === 'templates' ? it.only : it)('should import simple process (templates)', async function() { // given - const diagramXml = require('test/spec/element-templates/fixtures/complex.bpmn').default; + const diagramXml = (await import('test/spec/element-templates/fixtures/complex.bpmn')).default; - const elementTemplateContext = require.context('test/spec/element-templates/fixtures', false, /\.json$/); + const elementTemplateContext = import.meta.webpackContext('test/spec/element-templates/fixtures', { + recursive: false, + regExp: /\.json$/ + }); const elementTemplates = elementTemplateContext.keys().map(key => elementTemplateContext(key)).flat(); diff --git a/test/spec/cloud-element-templates/ElementTemplates.spec.js b/test/spec/cloud-element-templates/ElementTemplates.spec.js index 8c7ff238..e6c0ed16 100644 --- a/test/spec/cloud-element-templates/ElementTemplates.spec.js +++ b/test/spec/cloud-element-templates/ElementTemplates.spec.js @@ -346,10 +346,10 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { describe('createElement', function() { - it('should create element', inject(function(elementTemplates) { + it('should create element', inject(async function(elementTemplates) { // given - const templates = require('./fixtures/complex.json'); + const templates = (await import('./fixtures/complex.json')).default; // when const element = elementTemplates.createElement(templates[0]); @@ -363,28 +363,30 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { })); - it('should create element with bpmn:MessageEventDefinition', inject(function(elementTemplates) { + it('should create element with bpmn:MessageEventDefinition', inject( + async function(elementTemplates) { - // given - const templates = require('./fixtures/message.json'); + // given + const templates = (await import('./fixtures/message.json')).default; - // when - const element = elementTemplates.createElement(templates[0]); + // when + const element = elementTemplates.createElement(templates[0]); - const businessObject = getBusinessObject(element); - const eventDefinitions = businessObject.get('eventDefinitions'); + const businessObject = getBusinessObject(element); + const eventDefinitions = businessObject.get('eventDefinitions'); - // then - expect(businessObject.get('name')).to.eql('Message Event'); - expect(eventDefinitions).to.have.lengthOf(1); - expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; - })); + // then + expect(businessObject.get('name')).to.eql('Message Event'); + expect(eventDefinitions).to.have.lengthOf(1); + expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; + } + )); - it('should create message', inject(function(elementTemplates) { + it('should create message', inject(async function(elementTemplates) { // given - const templates = require('./fixtures/message.json'); + const templates = (await import('./fixtures/message.json')).default; // when const element = elementTemplates.createElement(templates[0]); @@ -418,75 +420,81 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { })); - it('should create message subscription', inject(function(elementTemplates) { + it('should create message subscription', inject( + async function(elementTemplates) { - // given - const templates = require('./fixtures/message.json'); + // given + const templates = (await import('./fixtures/message.json')).default; - // when - const element = elementTemplates.createElement(templates[1]); + // when + const element = elementTemplates.createElement(templates[1]); - const businessObject = getBusinessObject(element); - const eventDefinitions = businessObject.get('eventDefinitions'); + const businessObject = getBusinessObject(element); + const eventDefinitions = businessObject.get('eventDefinitions'); - // then - const message = eventDefinitions[0].get('messageRef'); + // then + const message = eventDefinitions[0].get('messageRef'); - expect(message).to.exist; + expect(message).to.exist; - const subscription = findExtension(message, 'zeebe:Subscription'); - expect(subscription).to.exist; - expect(subscription.get('correlationKey')).to.eql('=correlationKey'); - })); + const subscription = findExtension(message, 'zeebe:Subscription'); + expect(subscription).to.exist; + expect(subscription.get('correlationKey')).to.eql('=correlationKey'); + } + )); - it('should create message subscription (Send Task)', inject(function(elementTemplates) { + it('should create message subscription (Send Task)', inject( + function(elementTemplates) { - // given - const template = messageTemplates[3]; + // given + const template = messageTemplates[3]; - // when - const element = elementTemplates.createElement(template); + // when + const element = elementTemplates.createElement(template); - const businessObject = getBusinessObject(element); + const businessObject = getBusinessObject(element); - // then - const message = businessObject.get('messageRef'); + // then + const message = businessObject.get('messageRef'); - expect(message).to.exist; + expect(message).to.exist; - const subscription = findExtension(message, 'zeebe:Subscription'); - expect(subscription).to.exist; - expect(subscription.get('correlationKey')).to.eql('=correlationKey'); - })); + const subscription = findExtension(message, 'zeebe:Subscription'); + expect(subscription).to.exist; + expect(subscription.get('correlationKey')).to.eql('=correlationKey'); + } + )); - it('should not create conditional properties', inject(function(elementTemplates) { + it('should not create conditional properties', inject( + async function(elementTemplates) { - // given - const template = require('./fixtures/condition.json'); + // given + const template = (await import('./fixtures/condition.json')).default; - // when - const element = elementTemplates.createElement(template); + // when + const element = elementTemplates.createElement(template); - const businessObject = getBusinessObject(element); + const businessObject = getBusinessObject(element); - // then - // expect properties - expect(businessObject.get('customProperty')).to.be.undefined; + // then + // expect properties + expect(businessObject.get('customProperty')).to.be.undefined; - // expect ioMapping - const ioMapping = findExtension(businessObject, 'zeebe:IoMapping'); - expect(ioMapping).to.be.undefined; + // expect ioMapping + const ioMapping = findExtension(businessObject, 'zeebe:IoMapping'); + expect(ioMapping).to.be.undefined; - // expect taskHeaders - const taskHeaders = findExtension(businessObject, 'zeebe:TaskHeaders'); - expect(taskHeaders).to.be.undefined; + // expect taskHeaders + const taskHeaders = findExtension(businessObject, 'zeebe:TaskHeaders'); + expect(taskHeaders).to.be.undefined; - // expect taskDefinition - const taskDefinition = findExtension(businessObject, 'zeebe:TaskDefinition'); - expect(taskDefinition).to.be.undefined; - })); + // expect taskDefinition + const taskDefinition = findExtension(businessObject, 'zeebe:TaskDefinition'); + expect(taskDefinition).to.be.undefined; + } + )); it('should throw error - no template', inject(function(elementTemplates) { @@ -502,10 +510,10 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { it('integration', inject( - function(create, dragging, elementRegistry, elementTemplates) { + async function(create, dragging, elementRegistry, elementTemplates) { // given - const templates = require('./fixtures/complex.json'); + const templates = (await import('./fixtures/complex.json')).default; const processElement = elementRegistry.get('Process_1'); @@ -520,8 +528,8 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { // then expect(element).to.exist; expect(element.parent).to.eql(processElement); - }) - ); + } + )); }); @@ -569,57 +577,59 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { })); - it('should apply valid dynamic property binding', inject(function(elementRegistry, elementTemplates) { - - // given - elementTemplates.set([ - require('./fixtures/condition-dropdown-dynamic-values.json'), - require('./fixtures/condition-dropdown-dynamic-values-1.json') - ]); - - const template = elementTemplates.get('condition-dropdown-dynamic-values'); - const task = elementTemplates.applyTemplate(elementRegistry.get('Task_3'), template); + it('should apply valid dynamic property binding', inject( + async function(elementRegistry, elementTemplates) { - // assume - expect( - task.businessObject.extensionElements.values[0].inputParameters[0].source - ).to.eql( - 'action1' - ); + // given + elementTemplates.set([ + (await import('./fixtures/condition-dropdown-dynamic-values.json')).default, + (await import('./fixtures/condition-dropdown-dynamic-values-1.json')).default + ]); - expect( - task.businessObject.extensionElements.values[1].type - ).to.eql( - 'action1-value' - ); + const template = elementTemplates.get('condition-dropdown-dynamic-values'); + const task = elementTemplates.applyTemplate(elementRegistry.get('Task_3'), template); - // when - const newTemplate = elementTemplates.get('condition-dropdown-dynamic-values-1'); - const updatedTask = elementTemplates.applyTemplate(task, newTemplate); + // assume + expect( + task.businessObject.extensionElements.values[0].inputParameters[0].source + ).to.eql( + 'action1' + ); + + expect( + task.businessObject.extensionElements.values[1].type + ).to.eql( + 'action1-value' + ); - // then - expect(updatedTask).to.exist; + // when + const newTemplate = elementTemplates.get('condition-dropdown-dynamic-values-1'); + const updatedTask = elementTemplates.applyTemplate(task, newTemplate); - // assume - expect( - updatedTask.businessObject.extensionElements.values[0].inputParameters[0].source - ).to.eql( - 'action1' - ); + // then + expect(updatedTask).to.exist; - expect( - updatedTask.businessObject.extensionElements.values[1].type - ).to.eql( - 'action1-value-2' - ); - })); + // assume + expect( + updatedTask.businessObject.extensionElements.values[0].inputParameters[0].source + ).to.eql( + 'action1' + ); + + expect( + updatedTask.businessObject.extensionElements.values[1].type + ).to.eql( + 'action1-value-2' + ); + } + )); it('should apply start event template without event definition', inject( - function(elementRegistry, elementTemplates) { + async function(elementRegistry, elementTemplates) { // given - const templates = require('./fixtures/start-event.json'); + const templates = (await import('./fixtures/start-event.json')).default; elementTemplates.set(templates); const template = templates[0]; @@ -639,342 +649,377 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { const eventDefinitions = getBusinessObject(updatedEvent).get('eventDefinitions'); expect(eventDefinitions).to.be.empty; - }) - ); + } + )); - it('should apply event definition', inject(function(elementRegistry, elementTemplates) { + it('should apply event definition', inject( + async function(elementRegistry, elementTemplates) { - // given - const templates = require('./fixtures/message.json'); - elementTemplates.set(templates); + // given + const templates = (await import('./fixtures/message.json')).default; + elementTemplates.set(templates); - const template = templates[0]; - const event = elementRegistry.get('IntermediateThrow'); + const template = templates[0]; + const event = elementRegistry.get('IntermediateThrow'); - // assume - expect(template).to.exist; + // assume + expect(template).to.exist; - // when - const updatedEvent = elementTemplates.applyTemplate(event, template); + // when + const updatedEvent = elementTemplates.applyTemplate(event, template); - // then - expect(updatedEvent).to.exist; - expect(elementTemplates.get(updatedEvent)).to.equal(template); + // then + expect(updatedEvent).to.exist; + expect(elementTemplates.get(updatedEvent)).to.equal(template); - expect(is(updatedEvent, 'bpmn:IntermediateCatchEvent')).to.be.true; + expect(is(updatedEvent, 'bpmn:IntermediateCatchEvent')).to.be.true; - const eventDefinitions = getBusinessObject(updatedEvent).get('eventDefinitions'); - expect(eventDefinitions).to.have.length(1); - expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; - })); + const eventDefinitions = getBusinessObject(updatedEvent).get('eventDefinitions'); + expect(eventDefinitions).to.have.length(1); + expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; + } + )); - it('should replace existing event definition', inject(function(elementRegistry, elementTemplates) { + it('should replace existing event definition', inject( + async function(elementRegistry, elementTemplates) { - // given - const templates = require('./fixtures/message.json'); - elementTemplates.set(templates); + // given + const templates = (await import('./fixtures/message.json')).default; + elementTemplates.set(templates); - const template = templates[0]; - const event = elementRegistry.get('IntermediateCatchMessage'); - const oldMessageEventDefinition = getBusinessObject(event).get('eventDefinitions')[0]; + const template = templates[0]; + const event = elementRegistry.get('IntermediateCatchMessage'); + const oldMessageEventDefinition = getBusinessObject(event).get('eventDefinitions')[0]; - // assume - expect(template).to.exist; + // assume + expect(template).to.exist; - // when - const updatedEvent = elementTemplates.applyTemplate(event, template); + // when + const updatedEvent = elementTemplates.applyTemplate(event, template); - // then - expect(updatedEvent).to.exist; - expect(elementTemplates.get(updatedEvent)).to.equal(template); + // then + expect(updatedEvent).to.exist; + expect(elementTemplates.get(updatedEvent)).to.equal(template); - expect(is(updatedEvent, 'bpmn:IntermediateCatchEvent')).to.be.true; + expect(is(updatedEvent, 'bpmn:IntermediateCatchEvent')).to.be.true; - const eventDefinitions = getBusinessObject(updatedEvent).get('eventDefinitions'); - expect(eventDefinitions).to.have.length(1); - expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; - expect(eventDefinitions[0]).not.to.eql(oldMessageEventDefinition); - })); + const eventDefinitions = getBusinessObject(updatedEvent).get('eventDefinitions'); + expect(eventDefinitions).to.have.length(1); + expect(is(eventDefinitions[0], 'bpmn:MessageEventDefinition')).to.be.true; + expect(eventDefinitions[0]).not.to.eql(oldMessageEventDefinition); + } + )); - it('should apply message binding', inject(function(elementRegistry, elementTemplates) { + it('should apply message binding', inject( + async function(elementRegistry, elementTemplates) { - // given - const templates = require('./fixtures/message.json'); - elementTemplates.set(templates); + // given + const templates = (await import('./fixtures/message.json')).default; + elementTemplates.set(templates); - const template = templates[0]; - const event = elementRegistry.get('IntermediateCatchMessage'); + const template = templates[0]; + const event = elementRegistry.get('IntermediateCatchMessage'); - // assume - expect(template).to.exist; + // assume + expect(template).to.exist; - // when - const updatedEvent = elementTemplates.applyTemplate(event, template); + // when + const updatedEvent = elementTemplates.applyTemplate(event, template); - // then - const businessObject = getBusinessObject(updatedEvent); - const eventDefinitions = businessObject.get('eventDefinitions'); + // then + const businessObject = getBusinessObject(updatedEvent); + const eventDefinitions = businessObject.get('eventDefinitions'); - // then - const message = eventDefinitions[0].get('messageRef'); + // then + const message = eventDefinitions[0].get('messageRef'); - expect(message).to.exist; - expect(message.get('name')).to.eql('hiddenName'); - })); + expect(message).to.exist; + expect(message.get('name')).to.eql('hiddenName'); + } + )); - it('should apply message zeebe:subscription binding', inject(function(elementRegistry, elementTemplates) { + it('should apply message zeebe:subscription binding', inject( + async function(elementRegistry, elementTemplates) { - // given - const templates = require('./fixtures/message.json'); - elementTemplates.set(templates); + // given + const templates = (await import('./fixtures/message.json')).default; + elementTemplates.set(templates); - const template = templates[1]; - const event = elementRegistry.get('IntermediateCatchMessage'); + const template = templates[1]; + const event = elementRegistry.get('IntermediateCatchMessage'); - // assume - expect(template).to.exist; + // assume + expect(template).to.exist; - // when - const updatedEvent = elementTemplates.applyTemplate(event, template); + // when + const updatedEvent = elementTemplates.applyTemplate(event, template); - // then - const businessObject = getBusinessObject(updatedEvent); - const eventDefinitions = businessObject.get('eventDefinitions'); + // then + const businessObject = getBusinessObject(updatedEvent); + const eventDefinitions = businessObject.get('eventDefinitions'); - // then - const message = eventDefinitions[0].get('messageRef'); + // then + const message = eventDefinitions[0].get('messageRef'); - expect(message).to.exist; + expect(message).to.exist; - const subscription = findExtension(message, 'zeebe:Subscription'); - expect(subscription).to.exist; - expect(subscription.get('correlationKey')).to.eql('=correlationKey'); - })); + const subscription = findExtension(message, 'zeebe:Subscription'); + expect(subscription).to.exist; + expect(subscription.get('correlationKey')).to.eql('=correlationKey'); + } + )); - it('should fire elementTemplates.apply event', inject(function(elementRegistry, elementTemplates, eventBus) { + it('should fire elementTemplates.apply event', inject( + function(elementRegistry, elementTemplates, eventBus) { - // given - const task = elementRegistry.get('Task_1'); - const newTemplate = templates[6]; - const spy = sinon.spy(); + // given + const task = elementRegistry.get('Task_1'); + const newTemplate = templates[6]; + const spy = sinon.spy(); - eventBus.on('elementTemplates.apply', spy); + eventBus.on('elementTemplates.apply', spy); - // when - elementTemplates.applyTemplate(task, newTemplate); + // when + elementTemplates.applyTemplate(task, newTemplate); + + // then + expect(spy).to.have.been.calledOnce; + expect(spy.getCalls()[0].args[1]).to.eql({ + element: task, + newTemplate + }); + } + )); - // then - expect(spy).to.have.been.calledOnce; - expect(spy.getCalls()[0].args[1]).to.eql({ - element: task, - newTemplate - }); - })); }); describe('unlinkTemplate', function() { - it('should unlink task template', inject(function(elementRegistry, elementTemplates) { + it('should unlink task template', inject( + function(elementRegistry, elementTemplates) { - // given - const task = elementRegistry.get('Task_1'); + // given + const task = elementRegistry.get('Task_1'); - // when - elementTemplates.unlinkTemplate(task); + // when + elementTemplates.unlinkTemplate(task); - // then - const taskBo = getBusinessObject(task); + // then + const taskBo = getBusinessObject(task); - expect(taskBo.modelerTemplate).not.to.exist; - expect(taskBo.modelerTemplateVersion).not.to.exist; - expect(taskBo.name).to.equal('foo'); - })); + expect(taskBo.modelerTemplate).not.to.exist; + expect(taskBo.modelerTemplateVersion).not.to.exist; + expect(taskBo.name).to.equal('foo'); + } + )); - it('should remove template icon', inject(function(elementRegistry, elementTemplates) { + it('should remove template icon', inject( + function(elementRegistry, elementTemplates) { - // given - let task = elementRegistry.get('Task_2'); + // given + let task = elementRegistry.get('Task_2'); - // assume - expect(getBusinessObject(task).get('zeebe:modelerTemplateIcon')).to.exist; + // assume + expect(getBusinessObject(task).get('zeebe:modelerTemplateIcon')).to.exist; - // when - elementTemplates.unlinkTemplate(task); + // when + elementTemplates.unlinkTemplate(task); - // then - task = elementRegistry.get('Task_1'); - expect(getBusinessObject(task).get('zeebe:modelerTemplateIcon')).to.not.exist; - })); + // then + task = elementRegistry.get('Task_1'); + expect(getBusinessObject(task).get('zeebe:modelerTemplateIcon')).to.not.exist; + } + )); - it('should fire elementTemplates.unlink event', inject(function(elementRegistry, elementTemplates, eventBus) { - // given - const task = elementRegistry.get('Task_1'); - const spy = sinon.spy(); + it('should fire elementTemplates.unlink event', inject( + function(elementRegistry, elementTemplates, eventBus) { - eventBus.on('elementTemplates.unlink', spy); + // given + const task = elementRegistry.get('Task_1'); + const spy = sinon.spy(); - // when - elementTemplates.unlinkTemplate(task); + eventBus.on('elementTemplates.unlink', spy); + + // when + elementTemplates.unlinkTemplate(task); + + // then + expect(spy).to.have.been.calledOnce; + expect(spy.getCalls()[0].args[1]).to.eql({ + element: task + }); + } + )); - // then - expect(spy).to.have.been.calledOnce; - expect(spy.getCalls()[0].args[1]).to.eql({ - element: task - }); - })); }); describe('removeTemplate', function() { - it('should remove task template', inject(function(elementRegistry, elementTemplates) { + it('should remove task template', inject( + function(elementRegistry, elementTemplates) { - // given - let task = elementRegistry.get('Task_1'); + // given + let task = elementRegistry.get('Task_1'); - // when - task = elementTemplates.removeTemplate(task); + // when + task = elementTemplates.removeTemplate(task); - // then - const taskBo = getBusinessObject(task); - const label = getLabel(task); + // then + const taskBo = getBusinessObject(task); + const label = getLabel(task); - expect(taskBo.modelerTemplate).not.to.exist; - expect(taskBo.modelerTemplateVersion).not.to.exist; - expect(label).to.eql('foo'); - })); + expect(taskBo.modelerTemplate).not.to.exist; + expect(taskBo.modelerTemplateVersion).not.to.exist; + expect(label).to.eql('foo'); + } + )); - it('should remove default task template', inject(function(elementRegistry, elementTemplates) { + it('should remove default task template', inject( + function(elementRegistry, elementTemplates) { - // given - let task = elementRegistry.get('ServiceTask'); + // given + let task = elementRegistry.get('ServiceTask'); - // when - task = elementTemplates.removeTemplate(task); + // when + task = elementTemplates.removeTemplate(task); - // then - const taskBo = getBusinessObject(task); + // then + const taskBo = getBusinessObject(task); - expect(taskBo.modelerTemplate).not.to.exist; - expect(taskBo.modelerTemplateVersion).not.to.exist; - })); + expect(taskBo.modelerTemplate).not.to.exist; + expect(taskBo.modelerTemplateVersion).not.to.exist; + } + )); - it('should remove group template', inject(function(elementRegistry, elementTemplates) { + it('should remove group template', inject( + function(elementRegistry, elementTemplates) { - // given - let group = elementRegistry.get('Group_1'); + // given + let group = elementRegistry.get('Group_1'); - // when - group = elementTemplates.removeTemplate(group); + // when + group = elementTemplates.removeTemplate(group); - // then - const groupBo = getBusinessObject(group); - const label = getLabel(group); + // then + const groupBo = getBusinessObject(group); + const label = getLabel(group); - expect(groupBo.modelerTemplate).not.to.exist; - expect(groupBo.modelerTemplateVersion).not.to.exist; - expect(label).to.eql('Group Name'); - })); + expect(groupBo.modelerTemplate).not.to.exist; + expect(groupBo.modelerTemplateVersion).not.to.exist; + expect(label).to.eql('Group Name'); + } + )); - it('should remove annotation template', inject(function(elementRegistry, elementTemplates) { + it('should remove annotation template', inject( + function(elementRegistry, elementTemplates) { - // given - let annotation = elementRegistry.get('TextAnnotation_1'); + // given + let annotation = elementRegistry.get('TextAnnotation_1'); - // when - annotation = elementTemplates.removeTemplate(annotation); + // when + annotation = elementTemplates.removeTemplate(annotation); - // then - const annotationBo = getBusinessObject(annotation); - const label = getLabel(annotation); + // then + const annotationBo = getBusinessObject(annotation); + const label = getLabel(annotation); - expect(annotationBo.modelerTemplate).not.to.exist; - expect(annotationBo.modelerTemplateVersion).not.to.exist; - expect(label).to.eql('Text Annotation'); - })); + expect(annotationBo.modelerTemplate).not.to.exist; + expect(annotationBo.modelerTemplateVersion).not.to.exist; + expect(label).to.eql('Text Annotation'); + } + )); - it('should remove conditional event template', inject(function(elementRegistry, elementTemplates) { + it('should remove conditional event template', inject( + function(elementRegistry, elementTemplates) { - // given - let event = elementRegistry.get('ConditionalEvent'); + // given + let event = elementRegistry.get('ConditionalEvent'); - // when - event = elementTemplates.removeTemplate(event); + // when + event = elementTemplates.removeTemplate(event); - // then - const eventBo = getBusinessObject(event); + // then + const eventBo = getBusinessObject(event); - expect(eventBo.modelerTemplate).not.to.exist; - expect(eventBo.modelerTemplateVersion).not.to.exist; - expect(eventBo.eventDefinitions).to.have.length(1); - })); + expect(eventBo.modelerTemplate).not.to.exist; + expect(eventBo.modelerTemplateVersion).not.to.exist; + expect(eventBo.eventDefinitions).to.have.length(1); + } + )); - it('should remove process template', inject(function(elementRegistry, elementTemplates) { + it('should remove process template', inject( + function(elementRegistry, elementTemplates) { - // given - let process = elementRegistry.get('Process_1'); - const children = [ ...process.children ]; + // given + let process = elementRegistry.get('Process_1'); + const children = [ ...process.children ]; - // when - process = elementTemplates.removeTemplate(process); + // when + process = elementTemplates.removeTemplate(process); - // then - const processBo = getBusinessObject(process); + // then + const processBo = getBusinessObject(process); - expect(processBo.modelerTemplate).not.to.exist; - expect(processBo.modelerTemplateVersion).not.to.exist; - expect(process.children.length).to.eql(children.length); - })); + expect(processBo.modelerTemplate).not.to.exist; + expect(processBo.modelerTemplateVersion).not.to.exist; + expect(process.children.length).to.eql(children.length); + } + )); - it('should remove subprocess template (plane)', inject(function(elementRegistry, elementTemplates) { + it('should remove subprocess template (plane)', inject( + function(elementRegistry, elementTemplates) { - // given - let subprocess = elementRegistry.get('SubProcess_1'); - let subprocessPlane = elementRegistry.get('SubProcess_1_plane'); + // given + let subprocess = elementRegistry.get('SubProcess_1'); + let subprocessPlane = elementRegistry.get('SubProcess_1_plane'); - // when - subprocess = elementTemplates.removeTemplate(subprocessPlane); + // when + subprocess = elementTemplates.removeTemplate(subprocessPlane); - // then - const taskBo = getBusinessObject(subprocess); + // then + const taskBo = getBusinessObject(subprocess); - expect(taskBo.modelerTemplate).not.to.exist; - expect(taskBo.modelerTemplateVersion).not.to.exist; - expect(taskBo.flowElements).to.have.length(1); - })); + expect(taskBo.modelerTemplate).not.to.exist; + expect(taskBo.modelerTemplateVersion).not.to.exist; + expect(taskBo.flowElements).to.have.length(1); + } + )); - it('should fire elementTemplates.remove event', inject(function(elementRegistry, elementTemplates, eventBus) { + it('should fire elementTemplates.remove event', inject( + function(elementRegistry, elementTemplates, eventBus) { - // given - const task = elementRegistry.get('Task_1'); - const spy = sinon.spy(); + // given + const task = elementRegistry.get('Task_1'); + const spy = sinon.spy(); - eventBus.on('elementTemplates.remove', spy); + eventBus.on('elementTemplates.remove', spy); - // when - elementTemplates.removeTemplate(task); + // when + elementTemplates.removeTemplate(task); - // then - expect(spy).to.have.been.calledOnce; - expect(spy.getCalls()[0].args[1]).to.eql({ - element: task - }); - })); + // then + expect(spy).to.have.been.calledOnce; + expect(spy.getCalls()[0].args[1]).to.eql({ + element: task + }); + } + )); }); @@ -1024,26 +1069,28 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { })); - it('should update message event template', inject(function(elementRegistry, elementTemplates) { + it('should update message event template', inject( + function(elementRegistry, elementTemplates) { - // given - const newTemplate = messageTemplates.find( - template => template.id === 'updateTemplate' && template.version === 2); - let event = elementRegistry.get('MessageEvent'); + // given + const newTemplate = messageTemplates.find( + template => template.id === 'updateTemplate' && template.version === 2); + let event = elementRegistry.get('MessageEvent'); - // when - event = elementTemplates.applyTemplate(event, newTemplate); + // when + event = elementTemplates.applyTemplate(event, newTemplate); - // then - const eventBo = getBusinessObject(event); + // then + const eventBo = getBusinessObject(event); - expect(eventBo.modelerTemplate).to.eql('updateTemplate'); - expect(eventBo.modelerTemplateVersion).to.eql(2); + expect(eventBo.modelerTemplate).to.eql('updateTemplate'); + expect(eventBo.modelerTemplateVersion).to.eql(2); - const message = findMessage(eventBo); - expect(message.name).to.eql('version_2'); - })); + const message = findMessage(eventBo); + expect(message.name).to.eql('version_2'); + } + )); it('should update message event template but keep user-edited name', @@ -1071,27 +1118,29 @@ describe('provider/cloud-element-templates - ElementTemplates', function() { ); - it('should fire elementTemplates.update event', inject(function(elementRegistry, elementTemplates, eventBus) { + it('should fire elementTemplates.update event', inject( + function(elementRegistry, elementTemplates, eventBus) { - // given - const newTemplate = templates.find( - template => template.id === 'foo' && template.version === 2); + // given + const newTemplate = templates.find( + template => template.id === 'foo' && template.version === 2); - const task = elementRegistry.get('Task_1'); - const spy = sinon.spy(); + const task = elementRegistry.get('Task_1'); + const spy = sinon.spy(); - eventBus.on('elementTemplates.update', spy); + eventBus.on('elementTemplates.update', spy); - // when - elementTemplates.applyTemplate(task, newTemplate); + // when + elementTemplates.applyTemplate(task, newTemplate); - // then - expect(spy).to.have.been.calledOnce; - expect(spy.getCalls()[0].args[1]).to.eql({ - element: task, - newTemplate - }); - })); + // then + expect(spy).to.have.been.calledOnce; + expect(spy.getCalls()[0].args[1]).to.eql({ + element: task, + newTemplate + }); + } + )); }); }); diff --git a/test/spec/cloud-element-templates/properties/CustomProperties.spec copy.js b/test/spec/cloud-element-templates/properties/CustomProperties.spec copy.js index 1efd063f..c110d120 100644 --- a/test/spec/cloud-element-templates/properties/CustomProperties.spec copy.js +++ b/test/spec/cloud-element-templates/properties/CustomProperties.spec copy.js @@ -4,7 +4,6 @@ import { bootstrapPropertiesPanel, changeInput, getBpmnJS, - withPropertiesPanel, inject } from 'test/TestHelper'; @@ -1144,7 +1143,7 @@ describe('provider/cloud-element-templates - CustomProperties', function() { }); - withPropertiesPanel('>=1.3.0')('should be auto-resizable', async function() { + it('should be auto-resizable', async function() { // when await expectSelected('textTask'); diff --git a/test/spec/cloud-element-templates/properties/CustomProperties.spec.js b/test/spec/cloud-element-templates/properties/CustomProperties.spec.js index 7d429c22..681bd183 100644 --- a/test/spec/cloud-element-templates/properties/CustomProperties.spec.js +++ b/test/spec/cloud-element-templates/properties/CustomProperties.spec.js @@ -4,7 +4,6 @@ import { bootstrapPropertiesPanel, changeInput, getBpmnJS, - withPropertiesPanel, inject } from 'test/TestHelper'; @@ -1145,7 +1144,7 @@ describe('provider/cloud-element-templates - CustomProperties', function() { }); - withPropertiesPanel('>=1.3.0')('should be auto-resizable', async function() { + it('should be auto-resizable', async function() { // when await expectSelected('textTask'); diff --git a/test/testBundle.js b/test/testBundle.js index cd95a586..47431119 100644 --- a/test/testBundle.js +++ b/test/testBundle.js @@ -1,3 +1,6 @@ -const allTests = require.context('./spec', true, /.spec\.js$/); +const allTests = import.meta.webpackContext('./spec', { + recursive: true, + regExp: /.spec\.js$/ +}); allTests.keys().forEach(allTests); \ No newline at end of file