|
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
| 2 | + |
| 3 | +import { executeBuiltinTemplate } from '../templates/builtin.js'; |
| 4 | + |
| 5 | +const { mockLogError } = vi.hoisted(() => ({ mockLogError: vi.fn() })); |
| 6 | + |
| 7 | +vi.mock('../templates/remote.js', () => ({ |
| 8 | + runRemoteTemplateCommand: vi.fn(), |
| 9 | +})); |
| 10 | + |
| 11 | +vi.mock('@voidzero-dev/vite-plus-prompts', () => ({ |
| 12 | + log: { error: mockLogError }, |
| 13 | +})); |
| 14 | + |
| 15 | +const workspaceInfo = { |
| 16 | + rootDir: '/tmp/workspace', |
| 17 | +} as any; |
| 18 | + |
| 19 | +const baseTemplateInfo = { |
| 20 | + packageName: 'wage-meeting', |
| 21 | + targetDir: 'wage-meeting', |
| 22 | + args: [], |
| 23 | + envs: {}, |
| 24 | + type: 'builtin' as any, |
| 25 | + interactive: false, |
| 26 | +}; |
| 27 | + |
| 28 | +describe('executeBuiltinTemplate', () => { |
| 29 | + it('returns exitCode 1 for unknown vite: template', async () => { |
| 30 | + const { runRemoteTemplateCommand } = await import('../templates/remote.js'); |
| 31 | + |
| 32 | + const result = await executeBuiltinTemplate(workspaceInfo, { |
| 33 | + ...baseTemplateInfo, |
| 34 | + command: 'vite:test', |
| 35 | + }); |
| 36 | + |
| 37 | + expect(result.exitCode).toBe(1); |
| 38 | + expect(runRemoteTemplateCommand).not.toHaveBeenCalled(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('shows error message with template name and --list hint', async () => { |
| 42 | + mockLogError.mockClear(); |
| 43 | + |
| 44 | + await executeBuiltinTemplate(workspaceInfo, { |
| 45 | + ...baseTemplateInfo, |
| 46 | + command: 'vite:unknown', |
| 47 | + }); |
| 48 | + |
| 49 | + expect(mockLogError).toHaveBeenCalledOnce(); |
| 50 | + const message = mockLogError.mock.calls[0][0] as string; |
| 51 | + expect(message).toContain('vite:unknown'); |
| 52 | + expect(message).toContain('vp create --list'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('does not show error message in silent mode', async () => { |
| 56 | + mockLogError.mockClear(); |
| 57 | + |
| 58 | + await executeBuiltinTemplate( |
| 59 | + workspaceInfo, |
| 60 | + { ...baseTemplateInfo, command: 'vite:test' }, |
| 61 | + { silent: true }, |
| 62 | + ); |
| 63 | + |
| 64 | + expect(mockLogError).not.toHaveBeenCalled(); |
| 65 | + }); |
| 66 | +}); |
0 commit comments