UNPKG

@capawesome/cli

Version:

The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.

36 lines (35 loc) 1.19 kB
import { createRequire } from 'module'; import { defineConfig, processConfig } from '@robingenz/zli'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; const require = createRequire(import.meta.url); const pkg = require('../package.json'); const config = defineConfig({ meta: { name: pkg.name, version: pkg.version, description: pkg.description, }, commands: {}, }); describe('CLI', () => { let consoleSpy; let processExitSpy; beforeEach(() => { consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { }); processExitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined); }); afterEach(() => { vi.restoreAllMocks(); }); it('should display version when --version flag is used', () => { try { processConfig(config, ['--version']); } catch (error) { // The processConfig function calls process.exit which we mock // so we continue execution and check the mocks } expect(consoleSpy).toHaveBeenCalledWith(pkg.version); expect(processExitSpy).toHaveBeenCalledWith(0); }); });