refactor(core): Refactor cli command tests (no-changelog) (#9731)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-06-18 10:50:39 +02:00
committed by GitHub
parent fb73ec3994
commit 2d02c73fbd
9 changed files with 160 additions and 250 deletions

View File

@@ -2,27 +2,18 @@ import { InternalHooks } from '@/InternalHooks';
import { License } from '@/License';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { ClearLicenseCommand } from '@/commands/license/clear';
import { Config } from '@oclif/core';
import { setupTestCommand } from '@test-integration/utils/testCommand';
import { mockInstance } from '../../shared/mocking';
const oclifConfig = new Config({ root: __dirname });
beforeAll(async () => {
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
await oclifConfig.load();
});
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
const license = mockInstance(License);
const command = setupTestCommand(ClearLicenseCommand);
test('license:clear invokes shutdown() to release any floating entitlements', async () => {
const cmd = new ClearLicenseCommand([], oclifConfig);
await cmd.init();
const license = mockInstance(License);
await cmd.run();
await command.run();
expect(license.init).toHaveBeenCalledTimes(1);
expect(license.shutdown).toHaveBeenCalledTimes(1);
jest.restoreAllMocks();
});