forked from getsentry/XcodeBuildMCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulators.test.ts
More file actions
199 lines (168 loc) · 6.12 KB
/
simulators.test.ts
File metadata and controls
199 lines (168 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { describe, it, expect, beforeEach } from 'vitest';
import { z } from 'zod';
import simulatorsResource, { simulatorsResourceLogic } from '../simulators.ts';
import { createMockExecutor } from '../../../test-utils/mock-executors.ts';
describe('simulators resource', () => {
describe('Export Field Validation', () => {
it('should export correct uri', () => {
expect(simulatorsResource.uri).toBe('xcodebuildmcp://simulators');
});
it('should export correct description', () => {
expect(simulatorsResource.description).toBe(
'Available iOS simulators with their UUIDs and states',
);
});
it('should export correct mimeType', () => {
expect(simulatorsResource.mimeType).toBe('text/plain');
});
it('should export handler function', () => {
expect(typeof simulatorsResource.handler).toBe('function');
});
});
describe('Handler Functionality', () => {
it('should handle successful simulator data retrieval', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: JSON.stringify({
devices: {
'iOS 17.0': [
{
name: 'iPhone 15 Pro',
udid: 'ABC123-DEF456-GHI789',
state: 'Shutdown',
isAvailable: true,
},
],
},
}),
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents).toHaveLength(1);
expect(result.contents[0].text).toContain('Available iOS Simulators:');
expect(result.contents[0].text).toContain('iPhone 15 Pro');
expect(result.contents[0].text).toContain('ABC123-DEF456-GHI789');
});
it('should handle command execution failure', async () => {
const mockExecutor = createMockExecutor({
success: false,
output: '',
error: 'Command failed',
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents).toHaveLength(1);
expect(result.contents[0].text).toContain('Failed to list simulators');
expect(result.contents[0].text).toContain('Command failed');
});
it('should handle JSON parsing errors and fall back to text parsing', async () => {
const mockTextOutput = `== Devices ==
-- iOS 17.0 --
iPhone 15 (test-uuid-123) (Shutdown)`;
const mockExecutor = async (command: string[]) => {
// JSON command returns invalid JSON
if (command.includes('--json')) {
return {
success: true,
output: 'invalid json',
error: undefined,
process: { pid: 12345 },
};
}
// Text command returns valid text output
return {
success: true,
output: mockTextOutput,
error: undefined,
process: { pid: 12345 },
};
};
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents).toHaveLength(1);
expect(result.contents[0].text).toContain('iPhone 15 (test-uuid-123)');
expect(result.contents[0].text).toContain('iOS 17.0');
});
it('should handle spawn errors', async () => {
const mockExecutor = createMockExecutor(new Error('spawn xcrun ENOENT'));
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents).toHaveLength(1);
expect(result.contents[0].text).toContain('Failed to list simulators');
expect(result.contents[0].text).toContain('spawn xcrun ENOENT');
});
it('should handle empty simulator data', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: JSON.stringify({ devices: {} }),
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents).toHaveLength(1);
expect(result.contents[0].text).toContain('Available iOS Simulators:');
});
it('should handle booted simulators correctly', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: JSON.stringify({
devices: {
'iOS 17.0': [
{
name: 'iPhone 15 Pro',
udid: 'ABC123-DEF456-GHI789',
state: 'Booted',
isAvailable: true,
},
],
},
}),
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents[0].text).toContain('[Booted]');
});
it('should filter out unavailable simulators', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: JSON.stringify({
devices: {
'iOS 17.0': [
{
name: 'iPhone 15 Pro',
udid: 'ABC123-DEF456-GHI789',
state: 'Shutdown',
isAvailable: true,
},
{
name: 'iPhone 14',
udid: 'XYZ789-UVW456-RST123',
state: 'Shutdown',
isAvailable: false,
},
],
},
}),
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents[0].text).toContain('iPhone 15 Pro');
expect(result.contents[0].text).not.toContain('iPhone 14');
});
it('should include next steps guidance', async () => {
const mockExecutor = createMockExecutor({
success: true,
output: JSON.stringify({
devices: {
'iOS 17.0': [
{
name: 'iPhone 15 Pro',
udid: 'ABC123-DEF456-GHI789',
state: 'Shutdown',
isAvailable: true,
},
],
},
}),
});
const result = await simulatorsResourceLogic(mockExecutor);
expect(result.contents[0].text).toContain('Next Steps:');
expect(result.contents[0].text).toContain('boot_sim');
expect(result.contents[0].text).toContain('open_sim');
expect(result.contents[0].text).toContain('build_sim');
expect(result.contents[0].text).toContain('get_sim_app_path');
});
});
});