@camunda/task-testing
v4.0.1
Published
[](https://github.com/camunda/task-testing/actions/workflows/CI.yml)
Keywords
Readme
@camunda/task-testing
Run and test a single building block of your BPMN diagram.
Usage
import TaskTesting from '@camunda/task-testing';
function App() {
...
<TaskTesting
{ ...props }
>
<TaskTesting.Tab label="My dynamic tab" render={ ({ output }) => <div>...</div> } />
<TaskTesting.Tab label="My static tab">My static content</TaskTesting.Tab>
<TaskTesting.Link href="https://example.com" render={ ({ output }) => <div>...</div> } />
<TaskTesting.Link href="https://example.com">My static link</TaskTesting.Link>
</TaskTesting>
}Props
| Prop | Type | Required | Description |
|------|------|----------|-------------|
| injector | Object | yes | The didi injector from the bpmn-js modeler |
| api | TaskExecutionApi | yes | API object with methods for deploying, starting instances, and polling |
| isConnectionConfigured | boolean | yes | Whether a Camunda 8 connection is configured |
| config | Config | no | Input/output configuration for elements |
| onConfigChanged | (config: Config) => void | no | Called when the configuration changes |
| configureConnectionBannerTitle | string | no | Title for the connection banner (default: 'Connection required') |
| configureConnectionLabel | string | no | Label for the configure connection button (default: 'Configure') |
| onConfigureConnection | Function | no | Called when the user clicks the configure connection button |
| onTestTask | () => boolean \| Promise<boolean> | no | Called when the user clicks Test task. Return true to proceed, false to abort |
| operateBaseUrl | string | no | Base URL for Operate links |
| tasklistBaseUrl | string | no | Base URL for Tasklist links |
| documentationUrl | string | no | URL for the documentation link |
| onTaskExecutionStarted | (element) => void | no | Called when task execution starts |
| onTaskExecutionFinished | (element, result) => void | no | Called when task execution ends |
TaskExecutionApi
The api prop must implement the following methods. Each method should return a { success: true, response } or { success: false, error } object.
| Method | Description |
|--------|-------------|
| deploy() | Deploy the process definition |
| startInstance(processDefinitionKey, elementId, variables) | Start a process instance |
| getProcessInstance(processInstanceKey) | Search for a process instance |
| getProcessInstanceElementInstances(processInstanceKey) | Search element instances |
| getProcessInstanceIncident(processInstanceKey) | Search incidents |
| getProcessInstanceJobs(processInstanceKey) | Search jobs |
| getProcessInstanceMessageSubscriptions(processInstanceKey) | Search message subscriptions |
| getProcessInstanceUserTasks(processInstanceKey) | Search user tasks |
| getProcessInstanceVariables(processInstanceKey) | Search variables |
onTaskExecutionFinished result
The result parameter is a discriminated union:
success: true— Task completed successfully. ContainslastPolledResultandprocessInstanceKey.success: false— Task did not complete successfully. Containsreason:'incident'— An incident occurred (includesincidentdetails)'terminated'— Process instance was terminated'user.cancel'— User clicked cancel'user.selectionChanged'— User selected a different element'error'— Deployment or start failed (includeserrorwithmessage)
Plugins
Custom tabs and links can be added as children:
<TaskTesting.Tab>— Adds a tab to the output panellabel(string, required) — Tab labelrender(function) — Render function receiving{ output }, for dynamic contentchildren(ReactNode) — Static content (alternative torender)priority(number, default1000) — Higher priority tabs appear first
<TaskTesting.Link>— Adds a link to the output headerhref(string, required) — Link URLtarget(string) — Link target (e.g.'_blank')render(function) — Render function receiving{ output }, for dynamic contentchildren(ReactNode) — Static content (alternative torender)priority(number, default1000) — Higher priority links appear first
Development
Install the dependencies and spin up a local server at http://localhost:3000:
npm install
npm startIt requires a Camunda 8 instance to run.
We recommend using Camunda 8 Run for development.
You can configure your Camunda 8 environment in the demo/.env file.
Build
Run all tests and build the library:
npm run allLicense
MIT
