n8n/packages/nodes-base/test/nodes/ExecuteWorkflow.ts
Iván Ovejero 06fa6f1fb3
ci: Expand ESLint to tests in BE packages (no-changelog) (#6147)
* 🔧 Adjust base ESLint config

* 🔧 Adjust `lint` and `lintfix` in `nodes-base`

* 🔧 Include `test` and `utils` in `nodes-base`

* 📘 Convert JS tests to TS

* 👕 Apply lintfixes
2023-05-02 10:37:19 +02:00

27 lines
1,010 B
TypeScript

import { WorkflowExecute } from 'n8n-core';
import type { INodeTypes, IRun } 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) {
const executionMode = 'manual';
const workflowInstance = new Workflow({
id: 'test',
nodes: testData.input.workflowData.nodes,
connections: testData.input.workflowData.connections,
active: false,
nodeTypes,
});
const waitPromise = await createDeferredPromise<IRun>();
const nodeExecutionOrder: string[] = [];
const additionalData = Helpers.WorkflowExecuteAdditionalData(waitPromise, nodeExecutionOrder);
const workflowExecute = new WorkflowExecute(additionalData, executionMode);
const executionData = await workflowExecute.run(workflowInstance);
const result = await waitPromise.promise();
return { executionData, result, nodeExecutionOrder };
}