|
| 1 | +import { Command } from '@commander-js/extra-typings'; |
| 2 | +import { afterEach, beforeEach, expect, MockInstance, test, vi } from 'vitest'; |
| 3 | + |
| 4 | +import { version } from '../../src/commands/version'; |
| 5 | + |
| 6 | +vi.mock('chalk', () => ({ |
| 7 | + default: new Proxy( |
| 8 | + {}, |
| 9 | + { |
| 10 | + get: () => (str: string) => str, |
| 11 | + }, |
| 12 | + ), |
| 13 | +})); |
| 14 | + |
| 15 | +let consoleMock: MockInstance; |
| 16 | + |
| 17 | +beforeEach(() => { |
| 18 | + consoleMock = vi.spyOn(console, 'log').mockImplementation(() => null); |
| 19 | +}); |
| 20 | + |
| 21 | +afterEach(() => { |
| 22 | + consoleMock.mockReset(); |
| 23 | +}); |
| 24 | + |
| 25 | +test('properly configured Command instance', () => { |
| 26 | + expect(version).toBeInstanceOf(Command); |
| 27 | + expect(version.name()).toBe('version'); |
| 28 | + expect(version.description()).toBe('Display detailed version information'); |
| 29 | +}); |
| 30 | + |
| 31 | +test('displays version information when executed', async () => { |
| 32 | + await version.parseAsync([]); |
| 33 | + |
| 34 | + expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining('Version Information:')); |
| 35 | + |
| 36 | + expect(consoleMock).toHaveBeenCalledWith( |
| 37 | + expect.stringContaining(`CLI Version: ${process.env.npm_package_version}`), |
| 38 | + ); |
| 39 | + |
| 40 | + expect(consoleMock).toHaveBeenCalledWith( |
| 41 | + expect.stringContaining(`Node Version: ${process.version}`), |
| 42 | + ); |
| 43 | + |
| 44 | + expect(consoleMock).toHaveBeenCalledWith( |
| 45 | + expect.stringContaining(`Platform: ${process.platform} (${process.arch})`), |
| 46 | + ); |
| 47 | +}); |
0 commit comments