mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
refactor: Overhaul nodes-testing setup - Part 1 (no-changelog) (#14303)
This commit is contained in:
committed by
GitHub
parent
f85b851851
commit
73e8d76e13
39
packages/nodes-base/test/nodes/load-nodes-and-credentials.ts
Normal file
39
packages/nodes-base/test/nodes/load-nodes-and-credentials.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Service } from '@n8n/di';
|
||||
import { LazyPackageDirectoryLoader } from 'n8n-core';
|
||||
import type {
|
||||
ICredentialType,
|
||||
INodeType,
|
||||
IVersionedNodeType,
|
||||
KnownNodesAndCredentials,
|
||||
LoadedClass,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
@Service()
|
||||
export class LoadNodesAndCredentials {
|
||||
private loader: LazyPackageDirectoryLoader;
|
||||
|
||||
readonly known: KnownNodesAndCredentials = { nodes: {}, credentials: {} };
|
||||
|
||||
constructor(baseDir: string) {
|
||||
this.loader = new LazyPackageDirectoryLoader(baseDir);
|
||||
}
|
||||
|
||||
async init() {
|
||||
await this.loader.loadAll();
|
||||
this.known.credentials = this.loader.known.credentials;
|
||||
this.known.nodes = this.loader.known.nodes;
|
||||
}
|
||||
|
||||
recognizesCredential(credentialType: string): boolean {
|
||||
return credentialType in this.known.credentials;
|
||||
}
|
||||
|
||||
getCredential(credentialType: string): LoadedClass<ICredentialType> {
|
||||
return this.loader.getCredential(credentialType);
|
||||
}
|
||||
|
||||
getNode(fullNodeType: string): LoadedClass<INodeType | IVersionedNodeType> {
|
||||
const nodeType = fullNodeType.split('.')[1];
|
||||
return this.loader.getNode(nodeType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user