Skip to main content
Glama

iTerm MCP Server

by ferrislucas
SendControlCharacter.test.ts2.82 kB
// @ts-nocheck import { jest, describe, expect, test, beforeEach } from '@jest/globals'; import SendControlCharacter from '../../src/SendControlCharacter.js'; // Create a mock subclass that overrides the executeCommand method class MockSendControlCharacter extends SendControlCharacter { mockExecuteCommand = jest.fn(); protected async executeCommand(command: string): Promise<void> { this.mockExecuteCommand(command); return Promise.resolve(); } } describe('SendControlCharacter', () => { let sendControlCharacter: MockSendControlCharacter; beforeEach(() => { // Initialize our test subject sendControlCharacter = new MockSendControlCharacter(); sendControlCharacter.mockExecuteCommand.mockClear(); }); test('should send standard control character (Ctrl+C)', async () => { // Act await sendControlCharacter.send('C'); // Assert - C is ASCII 67, Ctrl+C is ASCII 3 (67-64) expect(sendControlCharacter.mockExecuteCommand).toHaveBeenCalledWith( expect.stringContaining('ASCII character 3') ); }); test('should handle lowercase letters correctly', async () => { // Act await sendControlCharacter.send('c'); // Assert expect(sendControlCharacter.mockExecuteCommand).toHaveBeenCalledWith( expect.stringContaining('ASCII character 3') ); }); test('should handle telnet escape character (Ctrl+])', async () => { // Act await sendControlCharacter.send(']'); // Assert - Group Separator (GS) is ASCII 29 expect(sendControlCharacter.mockExecuteCommand).toHaveBeenCalledWith( expect.stringContaining('ASCII character 29') ); }); test('should handle escape key', async () => { // Act await sendControlCharacter.send('ESC'); // Assert - Escape is ASCII 27 expect(sendControlCharacter.mockExecuteCommand).toHaveBeenCalledWith( expect.stringContaining('ASCII character 27') ); // Test with alternative format await sendControlCharacter.send('escape'); expect(sendControlCharacter.mockExecuteCommand).toHaveBeenCalledWith( expect.stringContaining('ASCII character 27') ); }); test('should throw an error for invalid control characters', async () => { // Act & Assert await expect(sendControlCharacter.send('123')).rejects.toThrow( 'Invalid control character letter' ); }); test('should throw an error when execution fails', async () => { // Arrange - Make the mock throw an error sendControlCharacter.mockExecuteCommand.mockImplementation(() => { throw new Error('Command execution failed'); }); // Act & Assert await expect(sendControlCharacter.send('C')).rejects.toThrow( 'Failed to send control character: Command execution failed' ); }); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ferrislucas/iterm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server