|
| 1 | +import path from 'node:path'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | +import { removeColorCodes } from '@code-pushup/test-utils'; |
| 4 | +import { formatCommandLog } from './format-command-log.js'; |
| 5 | + |
| 6 | +describe('formatCommandLog', () => { |
| 7 | + it('should format simple command', () => { |
| 8 | + const result = removeColorCodes( |
| 9 | + formatCommandLog('npx', ['command', '--verbose']), |
| 10 | + ); |
| 11 | + |
| 12 | + expect(result).toBe('$ npx command --verbose'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should format simple command with explicit process.cwd()', () => { |
| 16 | + const result = removeColorCodes( |
| 17 | + formatCommandLog('npx', ['command', '--verbose'], process.cwd()), |
| 18 | + ); |
| 19 | + |
| 20 | + expect(result).toBe('$ npx command --verbose'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should format simple command with relative cwd', () => { |
| 24 | + const result = removeColorCodes( |
| 25 | + formatCommandLog('npx', ['command', '--verbose'], './wololo'), |
| 26 | + ); |
| 27 | + |
| 28 | + expect(result).toBe(`wololo $ npx command --verbose`); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should format simple command with absolute non-current path converted to relative', () => { |
| 32 | + const result = removeColorCodes( |
| 33 | + formatCommandLog( |
| 34 | + 'npx', |
| 35 | + ['command', '--verbose'], |
| 36 | + path.join(process.cwd(), 'tmp'), |
| 37 | + ), |
| 38 | + ); |
| 39 | + expect(result).toBe('tmp $ npx command --verbose'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should format simple command with relative cwd in parent folder', () => { |
| 43 | + const result = removeColorCodes( |
| 44 | + formatCommandLog('npx', ['command', '--verbose'], '..'), |
| 45 | + ); |
| 46 | + |
| 47 | + expect(result).toBe(`.. $ npx command --verbose`); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should format simple command using relative path to parent directory', () => { |
| 51 | + const result = removeColorCodes( |
| 52 | + formatCommandLog( |
| 53 | + 'npx', |
| 54 | + ['command', '--verbose'], |
| 55 | + path.dirname(process.cwd()), |
| 56 | + ), |
| 57 | + ); |
| 58 | + |
| 59 | + expect(result).toBe('.. $ npx command --verbose'); |
| 60 | + }); |
| 61 | +}); |
0 commit comments