|
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import { handleDeprecatedOptions } from './handleDeprecatedOptions.js'; |
| 3 | + |
| 4 | +describe('handleDeprecatedOptions', () => { |
| 5 | + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + warnSpy.mockClear(); |
| 9 | + }); |
| 10 | + |
| 11 | + afterEach(() => { |
| 12 | + warnSpy.mockClear(); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should replace -rm with -c', () => { |
| 16 | + const result = handleDeprecatedOptions(['-rm']); |
| 17 | + expect(result).toEqual(['-c']); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should show deprecation warning for -rm', () => { |
| 21 | + handleDeprecatedOptions(['-rm']); |
| 22 | + expect(warnSpy).toHaveBeenCalledTimes(1); |
| 23 | + expect(warnSpy.mock.calls[0][0]).toContain('-rm'); |
| 24 | + expect(warnSpy.mock.calls[0][0]).toContain('-c'); |
| 25 | + expect(warnSpy.mock.calls[0][0]).toContain('v3.0'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should not modify other arguments', () => { |
| 29 | + const result = handleDeprecatedOptions(['--output-dir', 'src/api', '-o']); |
| 30 | + expect(result).toEqual(['--output-dir', 'src/api', '-o']); |
| 31 | + expect(warnSpy).not.toHaveBeenCalled(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should handle mixed arguments with deprecated option', () => { |
| 35 | + const result = handleDeprecatedOptions([ |
| 36 | + '--plugin', |
| 37 | + 'tanstack-query-react', |
| 38 | + '-rm', |
| 39 | + '-o', |
| 40 | + 'src/api', |
| 41 | + ]); |
| 42 | + expect(result).toEqual([ |
| 43 | + '--plugin', |
| 44 | + 'tanstack-query-react', |
| 45 | + '-c', |
| 46 | + '-o', |
| 47 | + 'src/api', |
| 48 | + ]); |
| 49 | + expect(warnSpy).toHaveBeenCalledTimes(1); |
| 50 | + }); |
| 51 | +}); |
0 commit comments