mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
test: Add unit testing to nodes (no-changelog) (#4890)
* 🧪 Add base for building unit testing within nodes * Improve helper functions * 🧪 If node test * 🧪 Airtable node test * 🧪 If node test improvements * 🧪 Airtable node test improvements * ♻️ cleanup node unit tests * ♻️ refactor getting node result data to use helper method * ⚡ removed unused variables * ♻️ Helper to read json files --------- Co-authored-by: Marcus <marcus@n8n.io> Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
24
packages/nodes-base/test/nodes/ExecuteWorkflow.ts
Normal file
24
packages/nodes-base/test/nodes/ExecuteWorkflow.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { WorkflowExecute } from 'n8n-core';
|
||||
import { createDeferredPromise, INodeTypes, IRun, Workflow } from 'n8n-workflow';
|
||||
import * as Helpers from './Helpers';
|
||||
|
||||
export async function executeWorkflow(testData, 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user