refactor(core): Overhaul commands setup. Add support for module commands (#16709)

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-07-01 19:14:22 +02:00
committed by GitHub
parent 346bc84093
commit 9f8d3d3bc8
41 changed files with 1061 additions and 541 deletions

View File

@@ -1,19 +1,14 @@
import { testDb } from '@n8n/backend-test-utils';
import { mockInstance } from '@n8n/backend-test-utils';
import type { Config } from '@oclif/core';
import { mock } from 'jest-mock-extended';
import type { Class } from 'n8n-core';
import type { CommandClass } from '@n8n/decorators';
import argvParser from 'yargs-parser';
import type { BaseCommand } from '@/commands/base-command';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { TelemetryEventRelay } from '@/events/relays/telemetry.event-relay';
mockInstance(MessageEventBus);
export const setupTestCommand = <T extends BaseCommand>(Command: Class<T>) => {
const config = mock<Config>();
config.runHook.mockResolvedValue({ successes: [], failures: [] });
export const setupTestCommand = <T extends CommandClass>(Command: T) => {
// mock SIGINT/SIGTERM registration
process.once = jest.fn();
process.exit = jest.fn() as never;
@@ -34,8 +29,9 @@ export const setupTestCommand = <T extends BaseCommand>(Command: Class<T>) => {
});
const run = async (argv: string[] = []) => {
const command = new Command(argv, config);
await command.init();
const command = new Command();
command.flags = argvParser(argv);
await command.init?.();
await command.run();
return command;
};