import assert from 'node:assert/strict' import type { SpawnOptions } from 'node:child_process' import { test } from 'vitest' import { spawnUpdaterProcess } from './updater-process' test('spawnUpdaterProcess hides the updater console and detaches the child on Windows', () => { const calls: Array<{ args: string[]; command: string; options: SpawnOptions }> = [] let unrefCalls = 0 const child = { pid: 4242, unref: () => { unrefCalls += 1 } } const result = spawnUpdaterProcess( 'hermes-setup.exe', ['--update', '--branch', 'main'], { cwd: 'C:\\Hermes', detached: true, stdio: 'ignore' }, { isWindows: true, spawnProcess: (command, args, options) => { calls.push({ args, command, options }) return child } } ) assert.equal(result, child) assert.equal(unrefCalls, 1) assert.deepEqual(calls, [ { args: ['--update', '--branch', 'main'], command: 'hermes-setup.exe', options: { cwd: 'C:\\Hermes', detached: true, stdio: 'ignore', windowsHide: true } } ]) }) test('spawnUpdaterProcess preserves updater options off Windows', () => { let capturedOptions: SpawnOptions | undefined spawnUpdaterProcess( 'hermes-setup', ['--update'], { detached: true, stdio: 'ignore' }, { isWindows: false, spawnProcess: (_command, _args, options) => { capturedOptions = options return { unref: () => {} } } } ) assert.deepEqual(capturedOptions, { detached: true, stdio: 'ignore' }) })