import { describe, expect, it } from 'vitest'; import { createDevServerWatchCommand } from './dev-server-watch.mjs'; describe('createDevServerWatchCommand', () => { it('uses the package default port and disables relay hosting by default', () => { const command = createDevServerWatchCommand({ platform: 'win32', env: {}, bunExecutable: '/opt/bun/bin/bun', }); expect(command.command).toBe('/opt/bun/bin/bun'); expect(command.args).toEqual(['--watch', 'server/index.js', '--port', '3001']); expect(command.spawnOptions.env.OPENCHAMBER_RELAY_HOST).toBe('off'); expect(command.spawnOptions.windowsHide).toBe(true); }); it('passes the configured port and relay host to the Bun watcher', () => { const command = createDevServerWatchCommand({ platform: 'win32', env: { OPENCHAMBER_PORT: '58992', OPENCHAMBER_RELAY_HOST: 'relay.example.test', }, bunExecutable: 'C:\\Tools\\Bun\\bun.exe', }); expect(command.args).toEqual(['--watch', 'server/index.js', '--port', '58992']); expect(command.spawnOptions.env.OPENCHAMBER_RELAY_HOST).toBe('relay.example.test'); }); it('rejects an invalid configured port before spawning', () => { expect(() => createDevServerWatchCommand({ platform: 'win32', env: { OPENCHAMBER_PORT: 'not-a-port' }, bunExecutable: 'bun', })).toThrow(/Invalid OPENCHAMBER_PORT/); }); it('preserves the nodemon watcher command outside Windows', () => { const command = createDevServerWatchCommand({ platform: 'linux', env: { OPENCHAMBER_PORT: '4200' }, bunExecutable: '/opt/bun/bin/bun', }); expect(command.command).toBe('/opt/bun/bin/bun'); expect(command.args).toEqual([ 'x', 'nodemon', '--watch', 'server', '--ext', 'js', '--exec', 'bun server/index.js --port 4200', ]); }); });