mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
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:
committed by
GitHub
parent
346bc84093
commit
9f8d3d3bc8
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user