diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2a26b..ef3748a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to [@bpmn-io/variable-resolver](https://github.com/bpmn-io/v ___Note:__ Yet to be released changes appear here._ +## 1.3.2 + +* `FIX`: accept empty script expression without error ([#42](https://github.com/bpmn-io/variable-resolver/pull/42)) + ## 1.3.1 * `FIX`: parse script task result as FEEL context ([#41](https://github.com/bpmn-io/variable-resolver/pull/41)) diff --git a/lib/zeebe/util/feelUtility.js b/lib/zeebe/util/feelUtility.js index f140dc2..57c89b5 100644 --- a/lib/zeebe/util/feelUtility.js +++ b/lib/zeebe/util/feelUtility.js @@ -213,12 +213,12 @@ function getIoExpression(variable, origin) { * * @param {ProcessVariable} variable * @param {djs.model.Base} origin - * @returns { expression: String} + * @returns {string} */ function getScriptExpression(variable, origin) { const script = getExtensionElementsList(origin, 'zeebe:Script')[0]; - if (!script) { + if (!script || !script.expression) { return; } diff --git a/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn b/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn new file mode 100644 index 0000000..64cd8c4 --- /dev/null +++ b/test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/zeebe/mappings/script-task.bpmn b/test/fixtures/zeebe/mappings/script-task.bpmn index a5cc86a..9fc5421 100644 --- a/test/fixtures/zeebe/mappings/script-task.bpmn +++ b/test/fixtures/zeebe/mappings/script-task.bpmn @@ -1,7 +1,7 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/test/spec/zeebe/Mappings.spec.js b/test/spec/zeebe/Mappings.spec.js index 475f89e..9d88f81 100644 --- a/test/spec/zeebe/Mappings.spec.js +++ b/test/spec/zeebe/Mappings.spec.js @@ -13,6 +13,7 @@ import primitivesXML from 'test/fixtures/zeebe/mappings/primitives.bpmn'; import mergingXML from 'test/fixtures/zeebe/mappings/merging.bpmn'; import scopeXML from 'test/fixtures/zeebe/mappings/scope.bpmn'; import scriptTaskXML from 'test/fixtures/zeebe/mappings/script-task.bpmn'; +import scriptTaskEmptyExpressionXML from 'test/fixtures/zeebe/mappings/script-task-empty-expression.bpmn'; import VariableProvider from 'lib/VariableProvider'; @@ -320,30 +321,55 @@ describe('ZeebeVariableResolver - Variable Mappings', function() { describe('Script Task', function() { - beforeEach(bootstrap(scriptTaskXML)); + describe('valid', function() { + beforeEach(bootstrap(scriptTaskXML)); - it('should add type annotation for script tasks', inject(async function(variableResolver, elementRegistry) { - // given - const root = elementRegistry.get('Process_1'); + it('should add type annotation for script tasks', inject(async function(variableResolver, elementRegistry) { - // when - const variables = await variableResolver.getVariablesForElement(root.businessObject); + // given + const element = elementRegistry.get('ScriptTask'); - // then - expect(variables).to.variableEqual([ - { - name: 'scriptResult', - type: 'Context', - info: '', - entries: [ - { name: 'foo', type: 'Number', info: '123', entries: [] }, - ] - } - ]); - })); + // when + const variables = await variableResolver.getVariablesForElement(element.businessObject); + + // then + expect(variables).to.variableEqual([ + { + name: 'scriptResult', + type: 'Context', + info: '', + entries: [ + { name: 'foo', type: 'Number', info: '123', entries: [] }, + ] + } + ]); + })); + }); + + + describe('empty expression', function() { + beforeEach(bootstrap(scriptTaskEmptyExpressionXML)); + + + it('should NOT error for empty expression', inject(async function(variableResolver, elementRegistry) { + + // given + const element = elementRegistry.get('ScriptTask'); + + // when + const variables = await variableResolver.getVariablesForElement(element.businessObject); + + // then + expect(variables).to.variableEqual([ + { + name: 'scriptResult' + } + ]); + })); + }); }); });