mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Refactor cli command tests (no-changelog) (#9731)
This commit is contained in:
committed by
GitHub
parent
fb73ec3994
commit
2d02c73fbd
37
packages/cli/test/integration/shared/utils/testCommand.ts
Normal file
37
packages/cli/test/integration/shared/utils/testCommand.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { Config } from '@oclif/core';
|
||||
import type { Class } from 'n8n-core';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
import type { BaseCommand } from '@/commands/BaseCommand';
|
||||
import * as testDb from '../testDb';
|
||||
|
||||
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();
|
||||
|
||||
beforeAll(async () => {
|
||||
await testDb.init();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user