mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
test: Automatically load workflow nodes in node tests (#5380)
test: automatically load workflow nodes in node tests
This commit is contained in:
@@ -44,8 +44,7 @@ describe('Execute Airtable Node', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodes: INodeType[] = [new ManualTrigger(), new Airtable()];
|
const nodeTypes = Helpers.setup(tests);
|
||||||
const nodeTypes = Helpers.setup(nodes);
|
|
||||||
|
|
||||||
for (const testData of tests) {
|
for (const testData of tests) {
|
||||||
test(testData.description, async () => {
|
test(testData.description, async () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import { Credentials } from 'n8n-core';
|
import { Credentials, loadClassInIsolation } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
ICredentialDataDecryptedObject,
|
ICredentialDataDecryptedObject,
|
||||||
ICredentialsHelper,
|
ICredentialsHelper,
|
||||||
@@ -18,11 +18,13 @@ import {
|
|||||||
IVersionedNodeType,
|
IVersionedNodeType,
|
||||||
IWorkflowBase,
|
IWorkflowBase,
|
||||||
IWorkflowExecuteAdditionalData,
|
IWorkflowExecuteAdditionalData,
|
||||||
|
LoadingDetails,
|
||||||
LoggerProxy,
|
LoggerProxy,
|
||||||
NodeHelpers,
|
NodeHelpers,
|
||||||
WorkflowHooks,
|
WorkflowHooks,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { WorkflowTestData } from './types';
|
import { WorkflowTestData } from './types';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export class CredentialsHelper extends ICredentialsHelper {
|
export class CredentialsHelper extends ICredentialsHelper {
|
||||||
async authenticate(
|
async authenticate(
|
||||||
@@ -143,11 +145,42 @@ export function NodeTypes(): NodeTypesClass {
|
|||||||
return nodeTypesInstance;
|
return nodeTypesInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setup(nodes: INodeType[]) {
|
let knownNodes: Record<string, LoadingDetails> | null = null;
|
||||||
const nodeTypes = NodeTypes();
|
|
||||||
for (const node of nodes) {
|
const loadKnownNodes = (): Record<string, LoadingDetails> => {
|
||||||
nodeTypes.addNode('n8n-nodes-base.' + node.description.name, node);
|
if (knownNodes === null) {
|
||||||
|
knownNodes = JSON.parse(readFileSync('dist/known/nodes.json').toString());
|
||||||
}
|
}
|
||||||
|
return knownNodes!;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function setup(testData: Array<WorkflowTestData> | WorkflowTestData) {
|
||||||
|
if (!Array.isArray(testData)) {
|
||||||
|
testData = [testData];
|
||||||
|
}
|
||||||
|
|
||||||
|
const knownNodes = loadKnownNodes();
|
||||||
|
|
||||||
|
const nodeTypes = NodeTypes();
|
||||||
|
const nodeNames = Array.from(
|
||||||
|
new Set(testData.flatMap((data) => data.input.workflowData.nodes.map((n) => n.type))),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const nodeName of nodeNames) {
|
||||||
|
if (!nodeName.startsWith('n8n-nodes-base.')) {
|
||||||
|
throw new Error(`Unknown node type: ${nodeName}`);
|
||||||
|
}
|
||||||
|
const loadInfo = knownNodes[nodeName.replace('n8n-nodes-base.', '')];
|
||||||
|
if (!loadInfo) {
|
||||||
|
throw new Error(`Unknown node type: ${nodeName}`);
|
||||||
|
}
|
||||||
|
const node = loadClassInIsolation(
|
||||||
|
path.join(process.cwd(), loadInfo.sourcePath),
|
||||||
|
loadInfo.className,
|
||||||
|
) as INodeType;
|
||||||
|
nodeTypes.addNode(nodeName, node);
|
||||||
|
}
|
||||||
|
|
||||||
const fakeLogger = {
|
const fakeLogger = {
|
||||||
log: () => {},
|
log: () => {},
|
||||||
debug: () => {},
|
debug: () => {},
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ describe('Execute If Node', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodes: INodeType[] = [new ManualTrigger(), new Code(), new Set(), new If(), new NoOp()];
|
const nodeTypes = Helpers.setup(tests);
|
||||||
const nodeTypes = Helpers.setup(nodes);
|
|
||||||
|
|
||||||
for (const testData of tests) {
|
for (const testData of tests) {
|
||||||
test(testData.description, async () => {
|
test(testData.description, async () => {
|
||||||
|
|||||||
@@ -177,8 +177,7 @@ describe('Execute Set Node', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodes: INodeType[] = [new Start(), new Set()];
|
const nodeTypes = Helpers.setup(tests);
|
||||||
const nodeTypes = Helpers.setup(nodes);
|
|
||||||
|
|
||||||
for (const testData of tests) {
|
for (const testData of tests) {
|
||||||
test(testData.description, async () => {
|
test(testData.description, async () => {
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ describe('Execute Start Node', () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodes: INodeType[] = [new Start()];
|
const nodeTypes = Helpers.setup(tests);
|
||||||
const nodeTypes = Helpers.setup(nodes);
|
|
||||||
|
|
||||||
for (const testData of tests) {
|
for (const testData of tests) {
|
||||||
test(testData.description, async () => {
|
test(testData.description, async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user