Skip to content

Commit

Permalink
fix: fix bug -> options?.debug, setup with debug mode via options.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
boyongjiong authored and wumail committed Sep 11, 2023
1 parent ad993c4 commit 1ed7d2a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 20 deletions.
20 changes: 14 additions & 6 deletions packages/engine/__test__/02_recorder.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Engine, { Recorder } from '../src/index';

describe('@logicflow/engine Recorder', () => {
Text('When init Engine with debug mode, getExecutionRecord will get null', async () => {
test('When init Engine with debug mode, getExecutionRecord will get null', async () => {
const engine = new Engine({
debug: true
debug: false
});
const flowData = {
/**
Expand Down Expand Up @@ -52,7 +52,9 @@ describe('@logicflow/engine Recorder', () => {
expect(execution).toBe(null)
});
test('Using the getExecutionRecord API, receive the complete execution record of the process.', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down Expand Up @@ -110,7 +112,9 @@ describe('@logicflow/engine Recorder', () => {
expect(executionIds.length).toBe(1);
});
test('The execution record cannot be obtained when the number of executions exceeds the maximum number of executions.', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down Expand Up @@ -174,11 +178,15 @@ describe('@logicflow/engine Recorder', () => {
},
global: {},
}
const engine = new Engine();
const engine = new Engine({
debug: true,
});
engine.load(flowData);
await engine.execute();
await engine.execute();
const engine1 = new Engine();
const engine1 = new Engine({
debug: true,
});
engine1.load(JSON.parse(JSON.stringify(flowData)));
await engine1.execute();

Expand Down
4 changes: 3 additions & 1 deletion packages/engine/__test__/03_condition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ 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 engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down
16 changes: 12 additions & 4 deletions packages/engine/__test__/04_execute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import Engine from '../src/index';

describe('@logicflow/engine Execute', () => {
test('When there are multiple start nodes in a process, all of them are executed by default.', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down Expand Up @@ -61,7 +63,9 @@ describe('@logicflow/engine Execute', () => {
expect(execution.length).toBe(5);
});
test('When there are multiple start nodes in a process, you can specify which start node to execute.', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down Expand Up @@ -124,7 +128,9 @@ describe('@logicflow/engine Execute', () => {
expect(execution[1].nodeId).toBe('node4');
});
test('When attempting to execute a non-existent start node in a process, an execution exception is raised.', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down Expand Up @@ -187,7 +193,9 @@ describe('@logicflow/engine Execute', () => {
}
});
test('When there are multiple start nodes in a process, parallel execution is supported, and each start node generates a unique execution ID', async () => {
const engine = new Engine();
const engine = new Engine({
debug: true,
});
const flowData = {
/**
* node1 |--> node2
Expand Down
11 changes: 8 additions & 3 deletions packages/engine/__test__/05_customNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ describe('@logicflow/engine Customize Node', () => {
getTime() {
return new Date().getTime();
}
}
},
debug: true,
});
engine.register({
type: 'DataNode',
Expand Down Expand Up @@ -105,12 +106,16 @@ describe('@logicflow/engine Customize Node', () => {
}
engine.load(flowData);
test('When the process is completed, the output field in the properties attribute of the last node is odd or even.', async () => {
const result = await engine.execute();
const result = await engine.execute({
debug: true,
});
const execution = await engine.getExecutionRecord(result.executionId);
expect(['odd', 'even'].indexOf(execution[execution.length - 1].properties.output) !== -1).toBe(true);
});
test('Execution records will contain return detail', async () => {
const result = await engine.execute();
const result = await engine.execute({
debug: true,
});
const execution = await engine.getExecutionRecord(result.executionId);
expect(execution[1].detail.customData).toBe('2')
})
Expand Down
8 changes: 6 additions & 2 deletions packages/engine/__test__/06_parallelExecution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ describe('@logicflow/engine parallel execution', () => {
})
}
}
const engine = new Engine();
const engine = new Engine({
debug: true,
});
engine.register({
type: 'FetchTask',
model: FetchNode,
Expand Down Expand Up @@ -76,7 +78,9 @@ describe('@logicflow/engine parallel execution', () => {
}
engine.load(flowData);
test('When the process is executed, the asynchronous node will not block the execution of other branch nodes.', async () => {
const result = await engine.execute();
const result = await engine.execute({
debug: true,
});
const execution = await engine.getExecutionRecord(result.executionId);
expect(execution.length).toBe(4);
expect(execution[3].nodeId).toEqual('node2')
Expand Down
8 changes: 6 additions & 2 deletions packages/engine/__test__/07_interruptedAndResume.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('@logicflow/engine interrupted and resume', () => {
})
}
}
const engine = new Engine();
const engine = new Engine({
debug: true,
});
engine.register({
type: 'UserTask',
model: UserTask,
Expand Down Expand Up @@ -107,7 +109,9 @@ describe('@logicflow/engine interrupted and resume', () => {
}
engine.load(flowData);
test('After executing the process, receive the flow status as "interrupted" and include detailed information returned by the custom node.', async () => {
const result = await engine.execute();
const result = await engine.execute({
debug: true,
});
expect(result.status).toBe('interrupted');
expect(result.detail.formId).toEqual('form_1');
});
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/__test__/08_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('@logicflow/engine error', () => {
getTime() {
return new Date().getTime();
}
}
},
debug: true,
});
engine.register({
type: 'DataNode',
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Engine {
constructor(options?: EngineConstructorOptions) {
this.nodeModelMap = new Map();
this.instanceId = createEngineId();
if (!options?.debug) {
if (options?.debug) {
this.recorder = new Recorder({
instanceId: this.instanceId,
});
Expand Down

0 comments on commit 1ed7d2a

Please sign in to comment.