mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +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:
48
packages/nodes-base/test/nodes/Start/StartNode.test.ts
Normal file
48
packages/nodes-base/test/nodes/Start/StartNode.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { INodeType } from 'n8n-workflow';
|
||||
import * as Helpers from '../Helpers';
|
||||
import { Start } from '../../../nodes/Start/Start.node';
|
||||
import { WorkflowTestData } from '../types';
|
||||
import { executeWorkflow } from '../ExecuteWorkflow';
|
||||
|
||||
describe('Execute Start Node', () => {
|
||||
const tests: Array<WorkflowTestData> = [
|
||||
{
|
||||
description: 'should run start node',
|
||||
input: {
|
||||
workflowData: {
|
||||
nodes: [
|
||||
{
|
||||
id: 'uuid-1',
|
||||
parameters: {},
|
||||
name: 'Start',
|
||||
type: 'n8n-nodes-base.start',
|
||||
typeVersion: 1,
|
||||
position: [100, 300],
|
||||
},
|
||||
],
|
||||
connections: {},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
nodeExecutionOrder: ['Start'],
|
||||
nodeData: {},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const nodes: INodeType[] = [new Start()];
|
||||
const nodeTypes = Helpers.setup(nodes);
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => {
|
||||
// execute workflow
|
||||
const { result, nodeExecutionOrder } = await executeWorkflow(testData, nodeTypes);
|
||||
// Check if the nodes did execute in the correct order
|
||||
expect(nodeExecutionOrder).toEqual(testData.output.nodeExecutionOrder);
|
||||
// Check if other data has correct value
|
||||
expect(result.finished).toEqual(true);
|
||||
expect(result.data.executionData!.contextData).toEqual({});
|
||||
expect(result.data.executionData!.nodeExecutionStack).toEqual([]);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user