|
| 1 | +import { Command } from 'commander'; |
| 2 | +import { execa } from 'execa'; |
| 3 | +import { expect, test, vi } from 'vitest'; |
| 4 | + |
| 5 | +import { start } from '../../src/commands/start'; |
| 6 | +import { program } from '../../src/program'; |
| 7 | + |
| 8 | +vi.mock('execa', () => ({ |
| 9 | + execa: vi.fn(() => Promise.resolve({})), |
| 10 | + __esModule: true, |
| 11 | +})); |
| 12 | + |
| 13 | +test('properly configured Command instance', () => { |
| 14 | + expect(start).toBeInstanceOf(Command); |
| 15 | + expect(start.name()).toBe('start'); |
| 16 | + expect(start.description()).toBe('Start your Catalyst storefront in optimized production mode.'); |
| 17 | + expect(start.options).toEqual( |
| 18 | + expect.arrayContaining([ |
| 19 | + expect.objectContaining({ flags: '-p, --port <number>', defaultValue: '3000' }), |
| 20 | + expect.objectContaining({ flags: '--root-dir <path>', defaultValue: process.cwd() }), |
| 21 | + ]), |
| 22 | + ); |
| 23 | +}); |
| 24 | + |
| 25 | +test('calls execa with Next.js production optimized server', async () => { |
| 26 | + await program.parseAsync([ |
| 27 | + 'node', |
| 28 | + 'catalyst', |
| 29 | + 'start', |
| 30 | + '-p', |
| 31 | + '3001', |
| 32 | + '--root-dir', |
| 33 | + '/path/to/root', |
| 34 | + ]); |
| 35 | + |
| 36 | + expect(execa).toHaveBeenCalledWith( |
| 37 | + '/path/to/root/node_modules/.bin/next', |
| 38 | + ['start', '-p', '3001'], |
| 39 | + expect.objectContaining({ |
| 40 | + stdio: 'inherit', |
| 41 | + cwd: '/path/to/root', |
| 42 | + }), |
| 43 | + ); |
| 44 | +}); |
0 commit comments