mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 14:09:43 -08:00
f667b384c9
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import type { Config } from '@oclif/core';
|
|
import type { Class } from 'n8n-core';
|
|
import { mock } from 'jest-mock-extended';
|
|
|
|
import type { BaseCommand } from '@/commands/base-command';
|
|
import * as testDb from '../testDb';
|
|
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
|
|
import { mockInstance } from '@test/mocking';
|
|
import { InternalHooks } from '@/internal-hooks';
|
|
|
|
mockInstance(InternalHooks);
|
|
|
|
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 };
|
|
};
|