|
| 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( |
| 29 | + `${path.join(process.cwd(), 'wololo')} $ npx command --verbose`, |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should format simple command with absolute cwd', () => { |
| 34 | + const result = removeColorCodes( |
| 35 | + formatCommandLog( |
| 36 | + 'npx', |
| 37 | + ['command', '--verbose'], |
| 38 | + '/tmp/path/to/somewhere', |
| 39 | + ), |
| 40 | + ); |
| 41 | + |
| 42 | + expect(result).toBe( |
| 43 | + `${path.resolve('/tmp/path/to/somewhere')} $ npx command --verbose`, |
| 44 | + ); |
| 45 | + }); |
| 46 | +}); |
0 commit comments