fix: clean up command runner capture listeners (#3748)

This commit is contained in:
Neil
2026-05-30 11:40:46 -07:00
committed by GitHub
parent 02e0faee5f
commit 7112c1c767
2 changed files with 53 additions and 11 deletions
+28
View File
@@ -112,6 +112,10 @@ describe('commandExecFileAsync Windows command shims', () => {
expect.objectContaining({ stdio: 'ignore', windowsHide: true })
)
expect(command.kill).not.toHaveBeenCalled()
expect(command.stdout.listenerCount('data')).toBe(0)
expect(command.stderr.listenerCount('data')).toBe(0)
expect(command.listenerCount('error')).toBe(0)
expect(command.listenerCount('close')).toBe(0)
})
})
@@ -137,6 +141,30 @@ describe('commandExecFileAsync Windows command shims', () => {
expect.objectContaining({ stdio: 'ignore', windowsHide: true })
)
expect(command.kill).not.toHaveBeenCalled()
expect(command.stdout.listenerCount('data')).toBe(0)
expect(command.stderr.listenerCount('data')).toBe(0)
expect(command.listenerCount('error')).toBe(0)
expect(command.listenerCount('close')).toBe(0)
})
})
it('removes listeners after successful Windows .cmd shim executions', async () => {
await withPlatform('win32', async () => {
const command = createMockChildProcess(1234)
spawnMock.mockReturnValue(command)
const promise = commandExecFileAsync('C:\\tools\\pnpm.cmd', ['--version'], {
cwd: 'C:\\repo'
})
command.stdout.emit('data', Buffer.from('9.1.0\n'))
command.stderr.emit('data', Buffer.from('notice\n'))
command.emit('close', 0)
await expect(promise).resolves.toEqual({ stdout: '9.1.0\n', stderr: 'notice\n' })
expect(command.stdout.listenerCount('data')).toBe(0)
expect(command.stderr.listenerCount('data')).toBe(0)
expect(command.listenerCount('error')).toBe(0)
expect(command.listenerCount('close')).toBe(0)
})
})
})