|
| 1 | +const { filesystem, system } = require('gluegun'); |
| 2 | + |
| 3 | +const src = filesystem.path(__dirname, '..'); |
| 4 | + |
| 5 | +const cli = async (cmd: string) => |
| 6 | + system.run(`node ${ filesystem.path(src, 'bin', 'lt') } ${cmd}`); |
| 7 | + |
| 8 | +describe('Utility Commands', () => { |
| 9 | + describe('lt status', () => { |
| 10 | + test('outputs project status', async () => { |
| 11 | + const output = await cli('status'); |
| 12 | + expect(output).toContain('Project Status'); |
| 13 | + expect(output).toContain('Directory:'); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('lt doctor', () => { |
| 18 | + test('runs doctor checks', async () => { |
| 19 | + const output = await cli('doctor'); |
| 20 | + expect(output).toContain('lt doctor'); |
| 21 | + // Check for doctor output (may contain ANSI codes) |
| 22 | + expect(output).toContain('Checks:'); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe('lt completion', () => { |
| 27 | + test('outputs help without arguments', async () => { |
| 28 | + const output = await cli('completion'); |
| 29 | + expect(output).toContain('Usage: lt completion'); |
| 30 | + expect(output).toContain('bash'); |
| 31 | + expect(output).toContain('zsh'); |
| 32 | + expect(output).toContain('fish'); |
| 33 | + }); |
| 34 | + |
| 35 | + test('generates bash completion', async () => { |
| 36 | + const output = await cli('completion bash'); |
| 37 | + expect(output).toContain('_lt_completions'); |
| 38 | + expect(output).toContain('complete -F _lt_completions lt'); |
| 39 | + }); |
| 40 | + |
| 41 | + test('generates zsh completion', async () => { |
| 42 | + const output = await cli('completion zsh'); |
| 43 | + expect(output).toContain('#compdef lt'); |
| 44 | + expect(output).toContain('_lt()'); |
| 45 | + }); |
| 46 | + |
| 47 | + test('generates fish completion', async () => { |
| 48 | + const output = await cli('completion fish'); |
| 49 | + expect(output).toContain('# lt completion for Fish shell'); |
| 50 | + expect(output).toContain('complete -f -c lt'); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('lt history', () => { |
| 55 | + test('outputs history or empty message', async () => { |
| 56 | + const output = await cli('history'); |
| 57 | + // Either shows history or "No command history yet" |
| 58 | + expect(output.includes('Command History') || output.includes('No command history')).toBe(true); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe('lt templates list', () => { |
| 63 | + test('lists available templates', async () => { |
| 64 | + const output = await cli('templates list'); |
| 65 | + expect(output).toContain('Available Templates'); |
| 66 | + expect(output).toContain('Built-in Templates'); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('lt config validate', () => { |
| 71 | + test('reports when no config file found', async () => { |
| 72 | + // Run in a temp directory without config |
| 73 | + const tempDir = filesystem.path(filesystem.homedir(), `.lt-test-${ Date.now()}`); |
| 74 | + filesystem.dir(tempDir); |
| 75 | + |
| 76 | + try { |
| 77 | + const output = await system.run( |
| 78 | + `cd ${tempDir} && node ${filesystem.path(src, 'bin', 'lt')} config validate` |
| 79 | + ); |
| 80 | + expect(output).toContain('No lt.config file found'); |
| 81 | + } finally { |
| 82 | + filesystem.remove(tempDir); |
| 83 | + } |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
| 87 | + |
| 88 | +describe('Dry-run flags', () => { |
| 89 | + describe('lt git clear --dry-run', () => { |
| 90 | + test('shows dry-run message', async () => { |
| 91 | + const output = await cli('git clear --dry-run'); |
| 92 | + expect(output).toContain('DRY-RUN MODE'); |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + describe('lt git clean --dry-run', () => { |
| 97 | + test('shows dry-run message', async () => { |
| 98 | + const output = await cli('git clean --dry-run'); |
| 99 | + expect(output).toContain('DRY-RUN MODE'); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments