-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1250 from towersxu/master
Add LogicFlow Engine
- Loading branch information
Showing
38 changed files
with
2,174 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# engine | ||
|
||
一个可以在JavaScript环境执行的流程引擎 | ||
|
||
## 使用方式 | ||
|
||
```shell | ||
npm test | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Engine from '../src/index'; | ||
|
||
describe('@logicflow/engine', () => { | ||
test('Execution Process Completed, Returning Data Containing executionId', async () => { | ||
const engine = new Engine(); | ||
const flowData = { | ||
graphData: { | ||
nodes: [ | ||
{ | ||
id: 'node1', | ||
type: 'StartNode', | ||
}, | ||
{ | ||
id: 'node2', | ||
type: 'TaskNode', | ||
} | ||
], | ||
edges: [ | ||
{ | ||
id: 'edge1', | ||
sourceNodeId: 'node1', | ||
targetNodeId: 'node2', | ||
} | ||
] | ||
}, | ||
context: {}, | ||
globalData: {}, | ||
} | ||
const flowModel = engine.load(flowData); | ||
const result = await engine.execute(); | ||
expect(engine).toBeInstanceOf(Engine); | ||
expect(flowModel.nodeConfigMap.size).toBe(flowData.graphData.nodes.length); | ||
expect(result).toHaveProperty('executionId'); | ||
expect(result.status).toBe('completed'); | ||
expect(result.nodeId).toEqual('node2'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Engine from '../src/index'; | ||
|
||
describe('@logicflow/engine Recorder', () => { | ||
test('Using the getExecutionRecord API, receive the complete execution record of the process.', async () => { | ||
const engine = new Engine(); | ||
const flowData = { | ||
graphData: { | ||
nodes: [ | ||
{ | ||
id: 'node1', | ||
type: 'StartNode', | ||
properties: {} | ||
}, | ||
{ | ||
id: 'node2', | ||
type: 'TaskNode', | ||
properties: {} | ||
} | ||
], | ||
edges: [ | ||
{ | ||
id: 'edge1', | ||
sourceNodeId: 'node1', | ||
targetNodeId: 'node2', | ||
} | ||
] | ||
}, | ||
global: {}, | ||
} | ||
engine.load(flowData); | ||
const result = await engine.execute(); | ||
const executionId = result.executionId; | ||
/** | ||
* [ | ||
* { | ||
* taskId: '', | ||
* nodeId: '', | ||
* instanceId: '', | ||
* nodeType: '', | ||
* timestamp: '', | ||
* properties: {}, | ||
* } | ||
* ] | ||
*/ | ||
const execution = await engine.getExecutionRecord(executionId); | ||
expect(execution.length).toBe(2); | ||
expect(execution[1]).toHaveProperty('taskId'); | ||
expect(execution[1]).toHaveProperty('nodeId'); | ||
expect(execution[1]).toHaveProperty('executionId'); | ||
expect(execution[1]).toHaveProperty('nodeType'); | ||
expect(execution[1]).toHaveProperty('timestamp'); | ||
expect(execution[1]).toHaveProperty('properties'); | ||
expect(execution[1].nodeId).toBe('node2'); | ||
expect(execution[1].nodeType).toBe('TaskNode'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Engine from '../src/index'; | ||
|
||
describe('@logicflow/engine condition', () => { | ||
test('The process will not continue its execution if the condition expression evaluates to false.', async () => { | ||
const engine = new Engine(); | ||
const flowData = { | ||
graphData: { | ||
nodes: [ | ||
{ | ||
id: 'node1', | ||
type: 'StartNode', | ||
properties: { | ||
} | ||
}, | ||
{ | ||
id: 'node2', | ||
type: 'TaskNode', | ||
properties: {} | ||
}, | ||
{ | ||
id: 'node3', | ||
type: 'TaskNode', | ||
properties: {} | ||
} | ||
], | ||
edges: [ | ||
{ | ||
id: 'edge1', | ||
sourceNodeId: 'node1', | ||
targetNodeId: 'node2', | ||
properties: { | ||
conditionExpression: 'a === 1' | ||
} | ||
}, | ||
{ | ||
id: 'edge2', | ||
sourceNodeId: 'node1', | ||
targetNodeId: 'node3', | ||
properties: { | ||
conditionExpression: 'a === 2' | ||
} | ||
} | ||
] | ||
}, | ||
globalData: { | ||
a: 2 | ||
}, | ||
} | ||
engine.load(flowData); | ||
const result = await engine.execute(); | ||
const execution = await engine.getExecutionRecord(result.executionId); | ||
expect(execution.length).toBe(2); | ||
expect(execution[1].nodeId).toBe('node3'); | ||
expect(execution[1].nodeType).toBe('TaskNode'); | ||
}); | ||
}); |
Oops, something went wrong.