n8n/packages/cli/test/integration/shared/utils/test-command.ts
Tomi Turtiainen 5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
refactor(core): Enable import/order eslint rule (#10794)
2024-09-12 19:07:18 +03:00

46 lines
1.1 KiB
TypeScript

import type { Config } from '@oclif/core';
import { mock } from 'jest-mock-extended';
import type { Class } from 'n8n-core';
import type { BaseCommand } from '@/commands/base-command';
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
import { mockInstance } from '@test/mocking';
import * as testDb from '../test-db';
mockInstance(MessageEventBus);
export const setupTestCommand = <T extends BaseCommand>(Command: Class<T>) => {
const config = mock<Config>();
config.runHook.mockResolvedValue({ successes: [], failures: [] });
// mock SIGINT/SIGTERM registration
process.once = jest.fn();
process.exit = jest.fn() as never;
beforeAll(async () => {
await testDb.init();
});
beforeEach(() => {
jest.clearAllMocks();
mockInstance(TelemetryEventRelay);
});
afterAll(async () => {
await testDb.terminate();
jest.restoreAllMocks();
});
const run = async (argv: string[] = []) => {
const command = new Command(argv, config);
await command.init();
await command.run();
return command;
};
return { run };
};