|
| 1 | +import{defineCommand}from'citty' |
| 2 | +import{describe,expect,it,vi}from'vitest' |
| 3 | + |
| 4 | +import{runCommandDef}from'../../src/run-command' |
| 5 | + |
| 6 | +letclear: boolean|undefined |
| 7 | + |
| 8 | +constdevCommand=defineCommand({ |
| 9 | +meta: {name: 'dev'}, |
| 10 | +args: { |
| 11 | +clear: { |
| 12 | +type: 'boolean', |
| 13 | +description: 'Clear console on restart', |
| 14 | +default: false, |
| 15 | +}, |
| 16 | +}, |
| 17 | +run(ctx){ |
| 18 | +clear=ctx.args.clear |
| 19 | +}, |
| 20 | +}) |
| 21 | + |
| 22 | +vi.mock('../../src/commands',()=>({ |
| 23 | +commands: { |
| 24 | +dev: ()=>Promise.resolve(devCommand), |
| 25 | +}, |
| 26 | +})) |
| 27 | + |
| 28 | +describe('runCommand',()=>{ |
| 29 | +it('should not clear the console unless asked to',async()=>{ |
| 30 | +const{ runCommand }=awaitimport('../../src/run') |
| 31 | + |
| 32 | +awaitrunCommand('dev',[]) |
| 33 | +expect(clear).toBe(false) |
| 34 | + |
| 35 | +awaitrunCommandDef(devCommand,[]) |
| 36 | +expect(clear).toBe(false) |
| 37 | +}) |
| 38 | + |
| 39 | +it('should respect an explicit `--clear`',async()=>{ |
| 40 | +const{ runCommand }=awaitimport('../../src/run') |
| 41 | + |
| 42 | +awaitrunCommand('dev',['--clear']) |
| 43 | +expect(clear).toBe(true) |
| 44 | + |
| 45 | +awaitrunCommandDef(devCommand,['--clear']) |
| 46 | +expect(clear).toBe(true) |
| 47 | +}) |
| 48 | + |
| 49 | +it('should not modify the arguments it is given',async()=>{ |
| 50 | +const{ runCommand }=awaitimport('../../src/run') |
| 51 | +constargv=['--clear'] |
| 52 | + |
| 53 | +awaitrunCommand('dev',argv) |
| 54 | +awaitrunCommandDef(devCommand,argv) |
| 55 | + |
| 56 | +expect(argv).toEqual(['--clear']) |
| 57 | +}) |
| 58 | +}) |
0 commit comments