Files
n8n/packages/core/nodes-testing/test-data-node.ts
alighasami 3d5eaf9445
Some checks failed
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
first commit
2026-03-17 16:22:57 +03:30

45 lines
1.3 KiB
TypeScript

import type {
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
/**
* A lightweight test-only node that outputs static JSON data.
* Used in test workflow JSON files as a replacement for Code nodes
* that merely return hardcoded data. Accepts a `data` parameter
* containing a JSON array (or single object) and emits each element
* as a workflow item. No sandbox or code execution involved.
*/
export class TestDataNode implements INodeType {
description: INodeTypeDescription = {
displayName: 'Test Data',
name: 'testData',
group: ['input'],
version: 1,
description: 'Provides static test data',
defaults: { name: 'Test Data' },
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
properties: [
{
displayName: 'Data',
name: 'data',
type: 'json',
default: '[]',
description: 'JSON array of items to output',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const raw = this.getNodeParameter('data', 0);
const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw;
const items: IDataObject[] = Array.isArray(parsed) ? parsed : [parsed];
return [items.map((item) => ({ json: item }))];
}
}