Skip to content

Commit

Permalink
hoist process output to definition environment on process error
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Apr 8, 2024
1 parent 941ae53 commit a76a2d2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# 13.2.0

- hoist process environment output to definition environment on process error
- major update of eslint
- use prettier for formatting rules, touched basically ALL files

# 13.1.2

- fix another lingering leave message. Now it was the definition execution that kept `process.leave` messages around for sentimental reasons
Expand Down
3 changes: 3 additions & 0 deletions dist/definition/DefinitionExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
}
this._stateChangeMessage(message, true);
switch (routingKey) {
case 'process.stop':
break;
case 'process.enter':
this[kStatus] = 'executing';
break;
Expand Down Expand Up @@ -427,6 +429,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
for (const bp of this[kProcesses].running.slice()) {
if (bp.id !== childId) bp.stop();
}
Object.assign(this.environment.output, content.output);
this._complete('error', {
error: content.error
});
Expand Down
2 changes: 2 additions & 0 deletions src/definition/DefinitionExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
if (bp.id !== childId) bp.stop();
}

Object.assign(this.environment.output, content.output);

this._complete('error', { error: content.error });
}
break;
Expand Down
77 changes: 77 additions & 0 deletions test/feature/definition-output-feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Definition from '../../src/definition/Definition.js';
import testHelpers from '../helpers/testHelpers.js';

Feature('Definition output', () => {
Scenario('Process completes with output', () => {
let definition;
Given('a process with output', async () => {
const source = `<?xml version="1.0" encoding="UTF-8"?>
<definitions id="script-definition" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" targetNamespace="http://bpmn.io/schema/bpmn">
<process id="my-process" isExecutable="true">
<scriptTask id="task" scriptFormat="js">
<script><![CDATA[
environment.output.foo = 'bar';
next();
]]>
</script>
</scriptTask>
</process>
</definitions>`;

const context = await testHelpers.context(source);
definition = new Definition(context);
});

let end;
When('ran', () => {
end = definition.waitFor('end');
definition.run();
});

Then('run completes', () => {
return end;
});

And('definition state contain hoisted process output', () => {
expect(definition.getState().environment.output).to.deep.equal({ foo: 'bar' });
});
});

Scenario('Process fails after writing output', () => {
let definition;
Given('a process with output', async () => {
const source = `<?xml version="1.0" encoding="UTF-8"?>
<definitions id="script-definition" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" targetNamespace="http://bpmn.io/schema/bpmn">
<process id="my-process" isExecutable="true">
<scriptTask id="task" scriptFormat="js">
<script><![CDATA[
environment.output.foo = 'bar';
baz();
next();
]]>
</script>
</scriptTask>
</process>
</definitions>`;

const context = await testHelpers.context(source);
definition = new Definition(context);
});

let errored;
When('ran', () => {
errored = definition.waitFor('error');
definition.run();
});

Then('run fails', () => {
return errored;
});

And('definition state contain hoisted process output', () => {
expect(definition.getState().environment.output).to.deep.equal({ foo: 'bar' });
});
});
});

0 comments on commit a76a2d2

Please sign in to comment.