UNPKG

archunit

Version:

ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app

178 lines 8.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const color_utils_1 = require("./color-utils"); describe('ColorUtils', () => { describe('color methods', () => { beforeEach(() => { // Mock stdout.isTTY to true to enable colors in tests Object.defineProperty(process.stdout, 'isTTY', { value: true, configurable: true, }); // Clear environment variables that disable colors delete process.env.NO_COLOR; delete process.env.CI; }); afterEach(() => { // Restore original environment delete process.env.NO_COLOR; delete process.env.CI; }); it('should apply red color', () => { const result = color_utils_1.ColorUtils.red('test'); expect(result).toContain('\x1b[31m'); // Red color code expect(result).toContain('test'); expect(result).toContain('\x1b[0m'); // Reset code }); it('should apply green color', () => { const result = color_utils_1.ColorUtils.green('test'); expect(result).toContain('\x1b[32m'); // Green color code expect(result).toContain('test'); }); it('should apply yellow color', () => { const result = color_utils_1.ColorUtils.yellow('test'); expect(result).toContain('\x1b[33m'); // Yellow color code expect(result).toContain('test'); }); it('should apply blue color', () => { const result = color_utils_1.ColorUtils.blue('test'); expect(result).toContain('\x1b[34m'); // Blue color code expect(result).toContain('test'); }); it('should apply magenta color', () => { const result = color_utils_1.ColorUtils.magenta('test'); expect(result).toContain('\x1b[35m'); // Magenta color code expect(result).toContain('test'); }); it('should apply cyan color', () => { const result = color_utils_1.ColorUtils.cyan('test'); expect(result).toContain('\x1b[36m'); // Cyan color code expect(result).toContain('test'); }); it('should apply gray color', () => { const result = color_utils_1.ColorUtils.gray('test'); expect(result).toContain('\x1b[90m'); // Gray color code expect(result).toContain('test'); }); it('should apply dim formatting', () => { const result = color_utils_1.ColorUtils.dim('test'); expect(result).toContain('\x1b[2m'); // Dim code expect(result).toContain('test'); }); it('should apply bold formatting', () => { const result = color_utils_1.ColorUtils.bold('test'); expect(result).toContain('\x1b[1m'); // Bold code expect(result).toContain('test'); }); it('should apply red bold formatting', () => { const result = color_utils_1.ColorUtils.redBold('test'); expect(result).toContain('\x1b[1m'); // Bold code expect(result).toContain('\x1b[31m'); // Red color code expect(result).toContain('test'); }); it('should apply green bold formatting', () => { const result = color_utils_1.ColorUtils.greenBold('test'); expect(result).toContain('\x1b[1m'); // Bold code expect(result).toContain('\x1b[32m'); // Green color code expect(result).toContain('test'); }); }); describe('color disabling', () => { it('should disable colors when NO_COLOR is set', () => { process.env.NO_COLOR = '1'; const result = color_utils_1.ColorUtils.red('test'); expect(result).toBe('test'); expect(result).not.toContain('\x1b['); }); it('should disable colors when CI is true', () => { process.env.CI = 'true'; const result = color_utils_1.ColorUtils.green('test'); expect(result).toBe('test'); expect(result).not.toContain('\x1b['); }); it('should disable colors when stdout is not a TTY', () => { Object.defineProperty(process.stdout, 'isTTY', { value: false, configurable: true, }); const result = color_utils_1.ColorUtils.blue('test'); expect(result).toBe('test'); expect(result).not.toContain('\x1b['); }); }); describe('formatFilePath', () => { beforeEach(() => { Object.defineProperty(process.stdout, 'isTTY', { value: true, configurable: true, }); delete process.env.NO_COLOR; delete process.env.CI; }); it('should format file path with line and column', () => { const result = color_utils_1.ColorUtils.formatFilePath('src/test.ts:10:5'); expect(result).toContain('\x1b[34m'); // Blue for file path //expect(result).toContain('\x1b[90m'); // Gray for line:column // removed this expect(result).toContain('src/test.ts'); expect(result).toContain(':10:5'); }); it('should handle paths with colons', () => { const result = color_utils_1.ColorUtils.formatFilePath('C:/Users/test/file.ts:10:5'); expect(result).toContain('C:/Users/test/file.ts'); expect(result).toContain(':10:5'); }); it('should handle paths without line:column', () => { const result = color_utils_1.ColorUtils.formatFilePath('src/test.ts'); expect(result).toContain('\x1b[34m'); // Blue for whole path expect(result).toContain('src/test.ts'); }); it('should handle paths with only one colon', () => { const result = color_utils_1.ColorUtils.formatFilePath('src/test.ts:10'); expect(result).toContain('\x1b[34m'); // Blue for whole path expect(result).toContain('src/test.ts:10'); }); }); describe('formatting methods', () => { beforeEach(() => { Object.defineProperty(process.stdout, 'isTTY', { value: true, configurable: true, }); delete process.env.NO_COLOR; delete process.env.CI; }); it('should format violation number', () => { const result = color_utils_1.ColorUtils.formatViolationNumber('1.'); expect(result).toContain('\x1b[1m'); // Bold expect(result).toContain('\x1b[31m'); // Red expect(result).toContain('1.'); }); it('should format violation type', () => { const result = color_utils_1.ColorUtils.formatViolationType('Error'); expect(result).toContain('\x1b[31m'); // Red expect(result).toContain('Error'); }); it('should format rule description', () => { const result = color_utils_1.ColorUtils.formatRule('This is a rule'); expect(result).toContain('\x1b[33m'); // Yellow expect(result).toContain('This is a rule'); }); it('should format metric value', () => { const result = color_utils_1.ColorUtils.formatMetricValue('42'); expect(result).toContain('\x1b[36m'); // Cyan expect(result).toContain('42'); }); it('should format success message', () => { const result = color_utils_1.ColorUtils.formatSuccess('All tests passed'); expect(result).toContain('\x1b[32m'); // Green expect(result).toContain('All tests passed'); }); it('should format error summary', () => { const result = color_utils_1.ColorUtils.formatErrorSummary('Tests failed'); expect(result).toContain('\x1b[1m'); // Bold expect(result).toContain('\x1b[31m'); // Red expect(result).toContain('Tests failed'); }); }); }); //# sourceMappingURL=color-utils.spec.js.map