|
1 | 1 | import { describe, expect, it, vi } from 'vitest'; |
2 | | -import { printDryRun } from '../../src/cli/commands/deploy.js'; |
| 2 | +import { cmdDeploy, printDryRun } from '../../src/cli/commands/deploy.js'; |
3 | 3 | import type { ShipnodeConfig } from '../../src/shared/types.js'; |
4 | 4 |
|
| 5 | +vi.mock('../../src/config/loader.js', () => ({ |
| 6 | + loadConfig: vi.fn(), |
| 7 | +})); |
| 8 | + |
5 | 9 | vi.mock('../../src/cli/ui.js', () => ({ |
6 | 10 | ui: { |
7 | 11 | banner: vi.fn(), |
| 12 | + error: vi.fn(), |
8 | 13 | note: vi.fn(), |
9 | 14 | }, |
10 | 15 | })); |
11 | 16 |
|
12 | 17 | const { ui } = await import('../../src/cli/ui.js'); |
| 18 | +const { loadConfig } = await import('../../src/config/loader.js'); |
13 | 19 |
|
14 | 20 | describe('deploy command dry run', () => { |
15 | | - it('shows the resolved single server target instead of default', () => { |
16 | | - const config: ShipnodeConfig = { |
17 | | - ssh: { host: '1.1.1.1', user: 'deploy', port: 22 }, |
18 | | - servers: { |
19 | | - app: { host: '1.1.1.1', user: 'deploy', port: 22 }, |
20 | | - }, |
21 | | - remotePath: '/var/www/app', |
22 | | - nodeVersion: 'lts', |
23 | | - apps: [{ |
24 | | - name: 'api', |
25 | | - appType: 'backend', |
26 | | - pm2: { apps: [{ name: 'api', port: 3000 }] }, |
27 | | - healthCheck: { enabled: true, path: '/health', timeout: 30, retries: 3, startupDelay: 3 }, |
28 | | - envFile: '.env', |
29 | | - keepReleases: 5, |
30 | | - }], |
31 | | - }; |
| 21 | + const config: ShipnodeConfig = { |
| 22 | + ssh: { host: '1.1.1.1', user: 'deploy', port: 22 }, |
| 23 | + servers: { |
| 24 | + app: { host: '1.1.1.1', user: 'deploy', port: 22 }, |
| 25 | + }, |
| 26 | + remotePath: '/var/www/app', |
| 27 | + nodeVersion: 'lts', |
| 28 | + apps: [{ |
| 29 | + name: 'api', |
| 30 | + appType: 'backend', |
| 31 | + pm2: { apps: [{ name: 'api', port: 3000 }] }, |
| 32 | + healthCheck: { enabled: true, path: '/health', timeout: 30, retries: 3, startupDelay: 3 }, |
| 33 | + envFile: '.env', |
| 34 | + keepReleases: 5, |
| 35 | + }], |
| 36 | + }; |
32 | 37 |
|
| 38 | + it('shows the resolved single server target instead of default', () => { |
33 | 39 | printDryRun(config, false); |
34 | 40 |
|
35 | 41 | expect(vi.mocked(ui.note).mock.calls[0]?.[0]).toContain('Server app'); |
36 | 42 | }); |
| 43 | + |
| 44 | + it('prints a clean error for an unknown dry-run app', async () => { |
| 45 | + vi.mocked(loadConfig).mockResolvedValue(config); |
| 46 | + const exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never); |
| 47 | + |
| 48 | + await cmdDeploy('/tmp/project', { dryRun: true, app: 'missing' }); |
| 49 | + |
| 50 | + expect(ui.error).toHaveBeenCalledWith('No app named "missing" in this workspace'); |
| 51 | + expect(exitSpy).toHaveBeenCalledWith(1); |
| 52 | + |
| 53 | + exitSpy.mockRestore(); |
| 54 | + }); |
37 | 55 | }); |
0 commit comments