2023-01-30 03:20:33 -08:00
|
|
|
import { WorkflowExecute } from 'n8n-core';
|
2023-08-01 08:32:30 -07:00
|
|
|
import type { INodeTypes, IRun, IRunExecutionData } from 'n8n-workflow';
|
2023-05-02 01:37:19 -07:00
|
|
|
import { createDeferredPromise, Workflow } from 'n8n-workflow';
|
2023-01-30 03:20:33 -08:00
|
|
|
import * as Helpers from './Helpers';
|
2023-02-07 01:27:37 -08:00
|
|
|
import type { WorkflowTestData } from './types';
|
2023-01-30 03:20:33 -08:00
|
|
|
|
2023-02-07 01:27:37 -08:00
|
|
|
export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INodeTypes) {
|
2023-08-01 08:32:30 -07:00
|
|
|
const executionMode = testData.trigger?.mode ?? 'manual';
|
2023-01-30 03:20:33 -08:00
|
|
|
const workflowInstance = new Workflow({
|
|
|
|
id: 'test',
|
|
|
|
nodes: testData.input.workflowData.nodes,
|
|
|
|
connections: testData.input.workflowData.connections,
|
|
|
|
active: false,
|
|
|
|
nodeTypes,
|
2023-07-05 09:47:34 -07:00
|
|
|
settings: testData.input.workflowData.settings,
|
2023-01-30 03:20:33 -08:00
|
|
|
});
|
|
|
|
const waitPromise = await createDeferredPromise<IRun>();
|
|
|
|
const nodeExecutionOrder: string[] = [];
|
2023-05-08 08:34:14 -07:00
|
|
|
const additionalData = Helpers.WorkflowExecuteAdditionalData(
|
|
|
|
waitPromise,
|
|
|
|
nodeExecutionOrder,
|
|
|
|
testData,
|
|
|
|
);
|
2023-01-30 03:20:33 -08:00
|
|
|
|
2023-08-01 08:32:30 -07:00
|
|
|
let executionData: IRun;
|
|
|
|
const runExecutionData: IRunExecutionData = {
|
|
|
|
resultData: {
|
|
|
|
runData: {},
|
|
|
|
},
|
|
|
|
executionData: {
|
|
|
|
contextData: {},
|
|
|
|
waitingExecution: {},
|
|
|
|
waitingExecutionSource: null,
|
|
|
|
nodeExecutionStack: [
|
|
|
|
{
|
|
|
|
node: workflowInstance.getStartNode()!,
|
|
|
|
data: {
|
|
|
|
main: [[testData.trigger?.input ?? { json: {} }]],
|
|
|
|
},
|
|
|
|
source: null,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const workflowExecute = new WorkflowExecute(additionalData, executionMode, runExecutionData);
|
|
|
|
executionData = await workflowExecute.processRunExecutionData(workflowInstance);
|
|
|
|
|
2023-01-30 03:20:33 -08:00
|
|
|
const result = await waitPromise.promise();
|
|
|
|
return { executionData, result, nodeExecutionOrder };
|
|
|
|
}
|