2024-06-18 01:50:39 -07:00
|
|
|
import type { Config } from '@oclif/core';
|
|
|
|
import type { Class } from 'n8n-core';
|
|
|
|
import { mock } from 'jest-mock-extended';
|
|
|
|
|
2024-08-22 02:10:37 -07:00
|
|
|
import type { BaseCommand } from '@/commands/base-command';
|
2024-06-18 01:50:39 -07:00
|
|
|
import * as testDb from '../testDb';
|
2024-08-02 07:52:49 -07:00
|
|
|
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
|
2024-07-17 02:56:27 -07:00
|
|
|
import { mockInstance } from '@test/mocking';
|
2024-08-22 02:10:37 -07:00
|
|
|
import { InternalHooks } from '@/internal-hooks';
|
2024-08-12 01:13:15 -07:00
|
|
|
|
|
|
|
mockInstance(InternalHooks);
|
2024-06-18 01:50:39 -07:00
|
|
|
|
|
|
|
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();
|
2024-07-04 09:07:47 -07:00
|
|
|
process.exit = jest.fn() as never;
|
2024-06-18 01:50:39 -07:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await testDb.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
2024-07-17 02:56:27 -07:00
|
|
|
mockInstance(TelemetryEventRelay);
|
2024-06-18 01:50:39 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
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 };
|
|
|
|
};
|