Skip to content

Commit 344aeba

Browse files
committed
refactor: extract build/test utilities, platform steps, and xcodebuild pipeline
1 parent d00ff56 commit 344aeba

33 files changed

+3900
-1064
lines changed
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { displayPath, formatToolPreflight } from '../build-preflight.ts';
3+
import { DERIVED_DATA_DIR } from '../log-paths.ts';
4+
5+
const DISPLAY_DERIVED_DATA = displayPath(DERIVED_DATA_DIR);
6+
7+
describe('formatToolPreflight', () => {
8+
it('formats simulator build with workspace and simulator name', () => {
9+
const result = formatToolPreflight({
10+
operation: 'Build',
11+
scheme: 'MyApp',
12+
workspacePath: '/path/to/MyApp.xcworkspace',
13+
configuration: 'Debug',
14+
platform: 'iOS Simulator',
15+
simulatorName: 'iPhone 17',
16+
});
17+
18+
expect(result).toBe(
19+
[
20+
'\u{1F528} Build',
21+
'',
22+
' Scheme: MyApp',
23+
' Workspace: /path/to/MyApp.xcworkspace',
24+
' Configuration: Debug',
25+
' Platform: iOS Simulator',
26+
' Simulator: iPhone 17',
27+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
28+
'',
29+
].join('\n'),
30+
);
31+
});
32+
33+
it('formats simulator build with project and simulator ID', () => {
34+
const result = formatToolPreflight({
35+
operation: 'Build',
36+
scheme: 'MyApp',
37+
projectPath: '/path/to/MyApp.xcodeproj',
38+
configuration: 'Release',
39+
platform: 'iOS Simulator',
40+
simulatorId: 'ABC-123-DEF',
41+
});
42+
43+
expect(result).toBe(
44+
[
45+
'\u{1F528} Build',
46+
'',
47+
' Scheme: MyApp',
48+
' Project: /path/to/MyApp.xcodeproj',
49+
' Configuration: Release',
50+
' Platform: iOS Simulator',
51+
' Simulator: ABC-123-DEF',
52+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
53+
'',
54+
].join('\n'),
55+
);
56+
});
57+
58+
it('formats build & run with device ID only', () => {
59+
const result = formatToolPreflight({
60+
operation: 'Build & Run',
61+
scheme: 'MyApp',
62+
projectPath: '/path/to/MyApp.xcodeproj',
63+
configuration: 'Debug',
64+
platform: 'iOS',
65+
deviceId: 'DEVICE-UDID-123',
66+
});
67+
68+
expect(result).toBe(
69+
[
70+
'\u{1F680} Build & Run',
71+
'',
72+
' Scheme: MyApp',
73+
' Project: /path/to/MyApp.xcodeproj',
74+
' Configuration: Debug',
75+
' Platform: iOS',
76+
' Device: DEVICE-UDID-123',
77+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
78+
'',
79+
].join('\n'),
80+
);
81+
});
82+
83+
it('formats build & run with device name and ID', () => {
84+
const result = formatToolPreflight({
85+
operation: 'Build & Run',
86+
scheme: 'MyApp',
87+
projectPath: '/path/to/MyApp.xcodeproj',
88+
configuration: 'Debug',
89+
platform: 'iOS',
90+
deviceId: 'DEVICE-UDID-123',
91+
deviceName: "Cameron's iPhone",
92+
});
93+
94+
expect(result).toBe(
95+
[
96+
'\u{1F680} Build & Run',
97+
'',
98+
' Scheme: MyApp',
99+
' Project: /path/to/MyApp.xcodeproj',
100+
' Configuration: Debug',
101+
' Platform: iOS',
102+
" Device: Cameron's iPhone (DEVICE-UDID-123)",
103+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
104+
'',
105+
].join('\n'),
106+
);
107+
});
108+
109+
it('formats macOS build & run with the approved front-matter spacing', () => {
110+
const result = formatToolPreflight({
111+
operation: 'Build & Run',
112+
scheme: 'MacApp',
113+
projectPath: '/path/to/MacApp.xcodeproj',
114+
configuration: 'Debug',
115+
platform: 'macOS',
116+
});
117+
118+
expect(result).toBe(
119+
[
120+
'\u{1F680} Build & Run',
121+
'',
122+
' Scheme: MacApp',
123+
' Project: /path/to/MacApp.xcodeproj',
124+
' Configuration: Debug',
125+
' Platform: macOS',
126+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
127+
'',
128+
].join('\n'),
129+
);
130+
});
131+
132+
it('formats macOS build with architecture', () => {
133+
const result = formatToolPreflight({
134+
operation: 'Build',
135+
scheme: 'MyMacApp',
136+
workspacePath: '/path/to/workspace.xcworkspace',
137+
configuration: 'Debug',
138+
platform: 'macOS',
139+
arch: 'arm64',
140+
});
141+
142+
expect(result).toBe(
143+
[
144+
'\u{1F528} Build',
145+
'',
146+
' Scheme: MyMacApp',
147+
' Workspace: /path/to/workspace.xcworkspace',
148+
' Configuration: Debug',
149+
' Platform: macOS',
150+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
151+
' Architecture: arm64',
152+
'',
153+
].join('\n'),
154+
);
155+
});
156+
157+
it('formats clean operation', () => {
158+
const result = formatToolPreflight({
159+
operation: 'Clean',
160+
scheme: 'MyApp',
161+
projectPath: '/path/to/MyApp.xcodeproj',
162+
configuration: 'Debug',
163+
platform: 'iOS',
164+
});
165+
166+
expect(result).toBe(
167+
[
168+
'\u{1F9F9} Clean',
169+
'',
170+
' Scheme: MyApp',
171+
' Project: /path/to/MyApp.xcodeproj',
172+
' Configuration: Debug',
173+
' Platform: iOS',
174+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
175+
'',
176+
].join('\n'),
177+
);
178+
});
179+
180+
it('omits workspace/project when neither provided', () => {
181+
const result = formatToolPreflight({
182+
operation: 'Build',
183+
scheme: 'MyApp',
184+
configuration: 'Debug',
185+
platform: 'macOS',
186+
});
187+
188+
expect(result).toBe(
189+
[
190+
'\u{1F528} Build',
191+
'',
192+
' Scheme: MyApp',
193+
' Configuration: Debug',
194+
' Platform: macOS',
195+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
196+
'',
197+
].join('\n'),
198+
);
199+
});
200+
201+
it('formats test operation', () => {
202+
const result = formatToolPreflight({
203+
operation: 'Test',
204+
scheme: 'MyApp',
205+
workspacePath: '/path/to/MyApp.xcworkspace',
206+
configuration: 'Debug',
207+
platform: 'iOS Simulator',
208+
simulatorName: 'iPhone 17',
209+
});
210+
211+
expect(result).toBe(
212+
[
213+
'\u{1F9EA} Test',
214+
'',
215+
' Scheme: MyApp',
216+
' Workspace: /path/to/MyApp.xcworkspace',
217+
' Configuration: Debug',
218+
' Platform: iOS Simulator',
219+
' Simulator: iPhone 17',
220+
` Derived Data: ${DISPLAY_DERIVED_DATA}`,
221+
'',
222+
].join('\n'),
223+
);
224+
});
225+
226+
it('shows relative path when under cwd', () => {
227+
const cwd = process.cwd();
228+
const result = formatToolPreflight({
229+
operation: 'Build',
230+
scheme: 'MyApp',
231+
workspacePath: `${cwd}/MyApp.xcworkspace`,
232+
configuration: 'Debug',
233+
platform: 'macOS',
234+
});
235+
236+
expect(result).toContain(' Workspace: MyApp.xcworkspace');
237+
expect(result).not.toContain(cwd);
238+
});
239+
240+
it('shows absolute path when outside cwd', () => {
241+
const result = formatToolPreflight({
242+
operation: 'Build',
243+
scheme: 'MyApp',
244+
projectPath: '/other/location/MyApp.xcodeproj',
245+
configuration: 'Debug',
246+
platform: 'macOS',
247+
});
248+
249+
expect(result).toContain(' Project: /other/location/MyApp.xcodeproj');
250+
});
251+
252+
it('prefers simulator name over simulator ID when both provided', () => {
253+
const result = formatToolPreflight({
254+
operation: 'Build',
255+
scheme: 'MyApp',
256+
configuration: 'Debug',
257+
platform: 'iOS Simulator',
258+
simulatorName: 'iPhone 17',
259+
simulatorId: 'ABC-123',
260+
});
261+
262+
expect(result).toContain('Simulator: iPhone 17');
263+
expect(result).not.toContain('ABC-123');
264+
});
265+
});

0 commit comments

Comments
 (0)