mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 17:14:05 -08:00
cef64329a9
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Benchmark Docker Image CI / build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import nock from 'nock';
|
|
import { WorkflowExecute } from 'n8n-core';
|
|
import type { INodeTypes, IRun, IRunExecutionData } from 'n8n-workflow';
|
|
import { createDeferredPromise, Workflow } from 'n8n-workflow';
|
|
import * as Helpers from './Helpers';
|
|
import type { WorkflowTestData } from './types';
|
|
|
|
export async function executeWorkflow(testData: WorkflowTestData, nodeTypes: INodeTypes) {
|
|
if (testData.nock) {
|
|
const { baseUrl, mocks } = testData.nock;
|
|
const agent = nock(baseUrl);
|
|
mocks.forEach(({ method, path, statusCode, requestBody, responseBody }) =>
|
|
agent[method](path, requestBody).reply(statusCode, responseBody),
|
|
);
|
|
}
|
|
const executionMode = testData.trigger?.mode ?? 'manual';
|
|
const workflowInstance = new Workflow({
|
|
id: 'test',
|
|
nodes: testData.input.workflowData.nodes,
|
|
connections: testData.input.workflowData.connections,
|
|
active: false,
|
|
nodeTypes,
|
|
settings: testData.input.workflowData.settings,
|
|
});
|
|
const waitPromise = createDeferredPromise<IRun>();
|
|
const nodeExecutionOrder: string[] = [];
|
|
const additionalData = Helpers.WorkflowExecuteAdditionalData(waitPromise, nodeExecutionOrder);
|
|
|
|
let executionData: IRun;
|
|
const runExecutionData: IRunExecutionData = {
|
|
resultData: {
|
|
runData: {},
|
|
},
|
|
executionData: {
|
|
metadata: {},
|
|
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);
|
|
|
|
const result = await waitPromise.promise;
|
|
return { executionData, result, nodeExecutionOrder };
|
|
}
|