first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import flatted from 'flatted';
|
||||
import type { IWorkflowBase } from 'n8n-workflow';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { workflow, trigger, node } from '../../../../../@n8n/workflow-sdk/src';
|
||||
import { test, expect } from '../../../fixtures/base';
|
||||
|
||||
const TRIGGER_NAME = 'Manual Trigger';
|
||||
const ALL_ITEMS_NODE_NAME = 'Code All Items';
|
||||
const EACH_ITEM_NODE_NAME = 'Code Each Item';
|
||||
|
||||
function createCodeNodeWorkflow(): IWorkflowBase {
|
||||
const manualTrigger = trigger({
|
||||
type: 'n8n-nodes-base.manualTrigger',
|
||||
version: 1,
|
||||
config: {
|
||||
name: TRIGGER_NAME,
|
||||
parameters: {},
|
||||
},
|
||||
});
|
||||
|
||||
const codeAllItems = node({
|
||||
type: 'n8n-nodes-base.code',
|
||||
version: 1,
|
||||
config: {
|
||||
name: ALL_ITEMS_NODE_NAME,
|
||||
parameters: {
|
||||
mode: 'runOnceForAllItems',
|
||||
jsCode: 'return [{ json: { value: 1 } }, { json: { value: 2 } }];',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const codeEachItem = node({
|
||||
type: 'n8n-nodes-base.code',
|
||||
version: 1,
|
||||
config: {
|
||||
name: EACH_ITEM_NODE_NAME,
|
||||
parameters: {
|
||||
mode: 'runOnceForEachItem',
|
||||
jsCode: 'return { json: { processed: $json.value * 2 } };',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const wf = workflow(nanoid(), `Code node test ${nanoid()}`)
|
||||
.add(manualTrigger.to(codeAllItems))
|
||||
.add(codeAllItems.to(codeEachItem));
|
||||
|
||||
const json = wf.toJSON() as IWorkflowBase;
|
||||
json.settings = { executionOrder: 'v1' };
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
test.describe(
|
||||
'Code node API execution @capability:task-runner',
|
||||
{
|
||||
annotation: [{ type: 'owner', description: 'NODES' }],
|
||||
},
|
||||
() => {
|
||||
test('should execute runOnceForAllItems and runOnceForEachItem code nodes successfully', async ({
|
||||
api,
|
||||
}) => {
|
||||
const { workflowId } = await api.workflows.createWorkflowFromDefinition(
|
||||
createCodeNodeWorkflow(),
|
||||
);
|
||||
|
||||
await api.workflows.runManually(workflowId, TRIGGER_NAME);
|
||||
|
||||
const execution = await api.workflows.waitForExecution(workflowId, 15_000, 'manual');
|
||||
expect(execution.status).toBe('success');
|
||||
|
||||
const fullExecution = await api.workflows.getExecution(execution.id);
|
||||
const executionData = flatted.parse(fullExecution.data);
|
||||
|
||||
// Verify runOnceForAllItems node produced correct output
|
||||
const allItemsOutput = executionData.resultData.runData[ALL_ITEMS_NODE_NAME];
|
||||
expect(allItemsOutput).toBeDefined();
|
||||
expect(allItemsOutput[0].data.main[0]).toEqual([
|
||||
expect.objectContaining({ json: { value: 1 } }),
|
||||
expect.objectContaining({ json: { value: 2 } }),
|
||||
]);
|
||||
|
||||
// Verify runOnceForEachItem node processed each item correctly
|
||||
const eachItemOutput = executionData.resultData.runData[EACH_ITEM_NODE_NAME];
|
||||
expect(eachItemOutput).toBeDefined();
|
||||
expect(eachItemOutput[0].data.main[0]).toEqual([
|
||||
expect.objectContaining({ json: { processed: 2 } }),
|
||||
expect.objectContaining({ json: { processed: 4 } }),
|
||||
]);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user