@ordojs/cli
Version:
Command-line interface for OrdoJS framework
55 lines (47 loc) • 1.68 kB
text/typescript
/**
* @fileoverview Tests for CLI error handling utilities
*/
import { describe, expect, it } from 'vitest';
import { CLIError, ErrorType, formatCompilationError, formatErrorWithLocation } from './error.js';
describe('CLI Error Handling', () => {
it('should create a CLIError with all properties', () => {
const error = new CLIError(
'Test error message',
ErrorType.VALIDATION,
'CLI-001',
['Suggestion 1', 'Suggestion 2']
);
expect(error.message).toBe('Test error message');
expect(error.type).toBe(ErrorType.VALIDATION);
expect(error.code).toBe('CLI-001');
expect(error.suggestions).toEqual(['Suggestion 1', 'Suggestion 2']);
expect(error.name).toBe('CLIError');
});
it('should format error with location', () => {
const formatted = formatErrorWithLocation(
'Syntax error',
'src/component.ordo',
10,
5
);
expect(formatted).toContain('error');
expect(formatted).toContain('src/component.ordo:10:5');
expect(formatted).toContain('Syntax error');
});
it('should format compilation error with suggestions', () => {
const formatted = formatCompilationError(
'Unexpected token',
'src/component.ordo',
10,
5,
'SYN-001',
['Check for missing semicolon', 'Verify bracket matching']
);
expect(formatted).toContain('Unexpected token');
expect(formatted).toContain('src/component.ordo:10:5');
expect(formatted).toContain('SYN-001');
expect(formatted).toContain('Suggestions:');
expect(formatted).toContain('Check for missing semicolon');
expect(formatted).toContain('Verify bracket matching');
});
});