|
| 1 | +/** |
| 2 | + * Lint Command Test Suite |
| 3 | + * |
| 4 | + * Tests the main lint command interface and option handling. |
| 5 | + * Includes both unit tests (type safety, interfaces) and integration tests |
| 6 | + * (actual command execution with real skill files). |
| 7 | + */ |
| 8 | + |
| 9 | +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; |
| 10 | +import { join, dirname } from 'path'; |
| 11 | +import { fileURLToPath } from 'url'; |
| 12 | +import { lintCommand, type LintOptions } from '../../../src/cli/commands/lint.js'; |
| 13 | + |
| 14 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 15 | +const projectRoot = join(__dirname, '../../..'); |
| 16 | +const testSkillPath = join(projectRoot, '../skills/ui5-best-practices'); |
| 17 | + |
| 18 | +describe('Lint Command CLI Interface', () => { |
| 19 | + describe('Type Definitions', () => { |
| 20 | + it('should have correct LintOptions interface', () => { |
| 21 | + const options: LintOptions = { |
| 22 | + format: 'json', |
| 23 | + output: './output.json', |
| 24 | + config: './.skilllintrc.json', |
| 25 | + structure: true, |
| 26 | + triggering: true, |
| 27 | + performance: true, |
| 28 | + integration: true, |
| 29 | + verbose: true, |
| 30 | + }; |
| 31 | + |
| 32 | + expect(options.format).toBe('json'); |
| 33 | + expect(options.output).toBe('./output.json'); |
| 34 | + expect(options.config).toBe('./.skilllintrc.json'); |
| 35 | + expect(options.structure).toBe(true); |
| 36 | + expect(options.triggering).toBe(true); |
| 37 | + expect(options.performance).toBe(true); |
| 38 | + expect(options.integration).toBe(true); |
| 39 | + expect(options.verbose).toBe(true); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should allow partial options', () => { |
| 43 | + const options: LintOptions = { |
| 44 | + format: 'text', |
| 45 | + }; |
| 46 | + |
| 47 | + expect(options.format).toBe('text'); |
| 48 | + expect(options.output).toBeUndefined(); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should allow empty options', () => { |
| 52 | + const options: LintOptions = {}; |
| 53 | + |
| 54 | + expect(Object.keys(options)).toHaveLength(0); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + describe('Format Options', () => { |
| 59 | + it('should support text format', () => { |
| 60 | + const options: LintOptions = { format: 'text' }; |
| 61 | + expect(options.format).toBe('text'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should support json format', () => { |
| 65 | + const options: LintOptions = { format: 'json' }; |
| 66 | + expect(options.format).toBe('json'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should support junit format', () => { |
| 70 | + const options: LintOptions = { format: 'junit' }; |
| 71 | + expect(options.format).toBe('junit'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should support codeclimate format', () => { |
| 75 | + const options: LintOptions = { format: 'codeclimate' }; |
| 76 | + expect(options.format).toBe('codeclimate'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should support github format', () => { |
| 80 | + const options: LintOptions = { format: 'github' }; |
| 81 | + expect(options.format).toBe('github'); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe('Scenario Options', () => { |
| 86 | + it('should support structure scenario', () => { |
| 87 | + const options: LintOptions = { structure: true }; |
| 88 | + expect(options.structure).toBe(true); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should support triggering scenario', () => { |
| 92 | + const options: LintOptions = { triggering: true }; |
| 93 | + expect(options.triggering).toBe(true); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should support performance scenario', () => { |
| 97 | + const options: LintOptions = { performance: true }; |
| 98 | + expect(options.performance).toBe(true); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should support integration scenario', () => { |
| 102 | + const options: LintOptions = { integration: true }; |
| 103 | + expect(options.integration).toBe(true); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should support multiple scenarios', () => { |
| 107 | + const options: LintOptions = { |
| 108 | + structure: true, |
| 109 | + triggering: true, |
| 110 | + performance: true, |
| 111 | + }; |
| 112 | + |
| 113 | + expect(options.structure).toBe(true); |
| 114 | + expect(options.triggering).toBe(true); |
| 115 | + expect(options.performance).toBe(true); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + describe('Output Options', () => { |
| 120 | + it('should accept output file path', () => { |
| 121 | + const options: LintOptions = { output: './results.json' }; |
| 122 | + expect(options.output).toBe('./results.json'); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should accept absolute output path', () => { |
| 126 | + const options: LintOptions = { output: '/tmp/results.json' }; |
| 127 | + expect(options.output).toBe('/tmp/results.json'); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('Config Options', () => { |
| 132 | + it('should accept config file path', () => { |
| 133 | + const options: LintOptions = { config: './custom.json' }; |
| 134 | + expect(options.config).toBe('./custom.json'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should accept absolute config path', () => { |
| 138 | + const options: LintOptions = { config: '/etc/skilllint.json' }; |
| 139 | + expect(options.config).toBe('/etc/skilllint.json'); |
| 140 | + }); |
| 141 | + }); |
| 142 | + |
| 143 | + describe('Verbose Option', () => { |
| 144 | + it('should support verbose flag', () => { |
| 145 | + const options: LintOptions = { verbose: true }; |
| 146 | + expect(options.verbose).toBe(true); |
| 147 | + }); |
| 148 | + |
| 149 | + it('should default verbose to undefined', () => { |
| 150 | + const options: LintOptions = {}; |
| 151 | + expect(options.verbose).toBeUndefined(); |
| 152 | + }); |
| 153 | + }); |
| 154 | + |
| 155 | + describe('Integration Tests', () => { |
| 156 | + let consoleLogSpy: ReturnType<typeof vi.spyOn>; |
| 157 | + let consoleErrorSpy: ReturnType<typeof vi.spyOn>; |
| 158 | + |
| 159 | + beforeEach(() => { |
| 160 | + consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); |
| 161 | + consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
| 162 | + }); |
| 163 | + |
| 164 | + afterEach(() => { |
| 165 | + consoleLogSpy.mockRestore(); |
| 166 | + consoleErrorSpy.mockRestore(); |
| 167 | + }); |
| 168 | + |
| 169 | + it('should execute lint command with real skill file', async () => { |
| 170 | + const exitCode = await lintCommand(testSkillPath, {}); |
| 171 | + |
| 172 | + // Should complete successfully (exit code 0 or 1 depending on validation results) |
| 173 | + expect(exitCode).toBeGreaterThanOrEqual(0); |
| 174 | + expect(exitCode).toBeLessThanOrEqual(2); |
| 175 | + }); |
| 176 | + |
| 177 | + it('should handle text format output', async () => { |
| 178 | + const exitCode = await lintCommand(testSkillPath, { format: 'text' }); |
| 179 | + |
| 180 | + expect(exitCode).toBeGreaterThanOrEqual(0); |
| 181 | + }); |
| 182 | + |
| 183 | + it('should handle json format output', async () => { |
| 184 | + const exitCode = await lintCommand(testSkillPath, { format: 'json' }); |
| 185 | + |
| 186 | + expect(exitCode).toBeGreaterThanOrEqual(0); |
| 187 | + }); |
| 188 | + |
| 189 | + it('should handle invalid path gracefully', async () => { |
| 190 | + const exitCode = await lintCommand('/nonexistent/path', {}); |
| 191 | + |
| 192 | + expect(exitCode).toBe(2); // Error exit code |
| 193 | + }); |
| 194 | + |
| 195 | + it('should handle structure scenario option', async () => { |
| 196 | + const exitCode = await lintCommand(testSkillPath, { structure: true }); |
| 197 | + |
| 198 | + expect(exitCode).toBeGreaterThanOrEqual(0); |
| 199 | + }); |
| 200 | + |
| 201 | + it('should handle multiple scenario options', async () => { |
| 202 | + const exitCode = await lintCommand(testSkillPath, { |
| 203 | + structure: true, |
| 204 | + triggering: true, |
| 205 | + performance: true, |
| 206 | + }); |
| 207 | + |
| 208 | + expect(exitCode).toBeGreaterThanOrEqual(0); |
| 209 | + }); |
| 210 | + }); |
| 211 | +}); |
| 212 | + |
0 commit comments