|
12 | 12 |
|
13 | 13 | const { |
14 | 14 | findXcodeProjectDirectory, |
| 15 | + runIosPrebuild, |
15 | 16 | runPodDeintegrate, |
16 | 17 | } = require('../prepare-app-utils'); |
17 | 18 |
|
@@ -174,6 +175,165 @@ describe('findXcodeProjectDirectory', () => { |
174 | 175 | }); |
175 | 176 | }); |
176 | 177 |
|
| 178 | +describe('runIosPrebuild', () => { |
| 179 | + let mockExecSync; |
| 180 | + let mockConsoleLog; |
| 181 | + let originalProcessEnv; |
| 182 | + |
| 183 | + beforeEach(() => { |
| 184 | + // Setup mocks |
| 185 | + const childProcess = require('child_process'); |
| 186 | + mockExecSync = childProcess.execSync; |
| 187 | + |
| 188 | + mockConsoleLog = console.log; |
| 189 | + |
| 190 | + // Store original process.env to restore later |
| 191 | + originalProcessEnv = process.env; |
| 192 | + |
| 193 | + // Reset all mocks |
| 194 | + jest.clearAllMocks(); |
| 195 | + }); |
| 196 | + |
| 197 | + afterEach(() => { |
| 198 | + // Restore original process.env |
| 199 | + process.env = originalProcessEnv; |
| 200 | + }); |
| 201 | + |
| 202 | + it('should run iOS prebuild successfully with nightly versions', async () => { |
| 203 | + // Setup |
| 204 | + const reactNativePath = '/path/to/react-native'; |
| 205 | + |
| 206 | + mockExecSync.mockReturnValue(undefined); |
| 207 | + |
| 208 | + // Execute |
| 209 | + await runIosPrebuild(reactNativePath); |
| 210 | + |
| 211 | + // Assert |
| 212 | + expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', { |
| 213 | + cwd: reactNativePath, |
| 214 | + env: { |
| 215 | + ...originalProcessEnv, |
| 216 | + RN_DEP_VERSION: 'nightly', |
| 217 | + HERMES_VERSION: 'nightly', |
| 218 | + }, |
| 219 | + stdio: 'inherit', |
| 220 | + }); |
| 221 | + expect(mockExecSync).toHaveBeenCalledTimes(1); |
| 222 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 223 | + 'Running iOS prebuild with nightly versions...', |
| 224 | + ); |
| 225 | + expect(mockConsoleLog).toHaveBeenCalledWith('✓ iOS prebuild completed'); |
| 226 | + expect(mockConsoleLog).toHaveBeenCalledTimes(2); |
| 227 | + }); |
| 228 | + |
| 229 | + it('should handle different React Native paths', async () => { |
| 230 | + // Setup |
| 231 | + const reactNativePath = '/Users/developer/react-native'; |
| 232 | + |
| 233 | + mockExecSync.mockReturnValue(undefined); |
| 234 | + |
| 235 | + // Execute |
| 236 | + await runIosPrebuild(reactNativePath); |
| 237 | + |
| 238 | + // Assert |
| 239 | + expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', { |
| 240 | + cwd: reactNativePath, |
| 241 | + env: { |
| 242 | + ...originalProcessEnv, |
| 243 | + RN_DEP_VERSION: 'nightly', |
| 244 | + HERMES_VERSION: 'nightly', |
| 245 | + }, |
| 246 | + stdio: 'inherit', |
| 247 | + }); |
| 248 | + }); |
| 249 | + |
| 250 | + it('should handle paths with spaces correctly', async () => { |
| 251 | + // Setup |
| 252 | + const reactNativePath = '/path/to/react native project'; |
| 253 | + |
| 254 | + mockExecSync.mockReturnValue(undefined); |
| 255 | + |
| 256 | + // Execute |
| 257 | + await runIosPrebuild(reactNativePath); |
| 258 | + |
| 259 | + // Assert |
| 260 | + expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', { |
| 261 | + cwd: reactNativePath, |
| 262 | + env: { |
| 263 | + ...originalProcessEnv, |
| 264 | + RN_DEP_VERSION: 'nightly', |
| 265 | + HERMES_VERSION: 'nightly', |
| 266 | + }, |
| 267 | + stdio: 'inherit', |
| 268 | + }); |
| 269 | + }); |
| 270 | + |
| 271 | + it('should throw error when iOS prebuild fails', async () => { |
| 272 | + // Setup |
| 273 | + const reactNativePath = '/path/to/react-native'; |
| 274 | + const mockError = new Error('Build failed'); |
| 275 | + |
| 276 | + mockExecSync.mockImplementation(() => { |
| 277 | + throw mockError; |
| 278 | + }); |
| 279 | + |
| 280 | + // Execute & Assert |
| 281 | + await expect(runIosPrebuild(reactNativePath)).rejects.toThrow( |
| 282 | + 'iOS prebuild failed: Build failed', |
| 283 | + ); |
| 284 | + |
| 285 | + expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', { |
| 286 | + cwd: reactNativePath, |
| 287 | + env: { |
| 288 | + ...originalProcessEnv, |
| 289 | + RN_DEP_VERSION: 'nightly', |
| 290 | + HERMES_VERSION: 'nightly', |
| 291 | + }, |
| 292 | + stdio: 'inherit', |
| 293 | + }); |
| 294 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 295 | + 'Running iOS prebuild with nightly versions...', |
| 296 | + ); |
| 297 | + expect(mockConsoleLog).not.toHaveBeenCalledWith('✓ iOS prebuild completed'); |
| 298 | + }); |
| 299 | + |
| 300 | + it('should handle script not found error', async () => { |
| 301 | + // Setup |
| 302 | + const reactNativePath = '/path/to/react-native'; |
| 303 | + const mockError = new Error('Cannot find module scripts/ios-prebuild'); |
| 304 | + |
| 305 | + mockExecSync.mockImplementation(() => { |
| 306 | + throw mockError; |
| 307 | + }); |
| 308 | + |
| 309 | + // Execute & Assert |
| 310 | + await expect(runIosPrebuild(reactNativePath)).rejects.toThrow( |
| 311 | + 'iOS prebuild failed: Cannot find module scripts/ios-prebuild', |
| 312 | + ); |
| 313 | + }); |
| 314 | + |
| 315 | + it('should handle root directory path', async () => { |
| 316 | + // Setup |
| 317 | + const reactNativePath = '/'; |
| 318 | + |
| 319 | + mockExecSync.mockReturnValue(undefined); |
| 320 | + |
| 321 | + // Execute |
| 322 | + await runIosPrebuild(reactNativePath); |
| 323 | + |
| 324 | + // Assert |
| 325 | + expect(mockExecSync).toHaveBeenCalledWith('node scripts/ios-prebuild -s', { |
| 326 | + cwd: '/', |
| 327 | + env: { |
| 328 | + ...originalProcessEnv, |
| 329 | + RN_DEP_VERSION: 'nightly', |
| 330 | + HERMES_VERSION: 'nightly', |
| 331 | + }, |
| 332 | + stdio: 'inherit', |
| 333 | + }); |
| 334 | + }); |
| 335 | +}); |
| 336 | + |
177 | 337 | describe('runPodDeintegrate', () => { |
178 | 338 | let mockExecSync; |
179 | 339 | let mockConsoleLog; |
|
0 commit comments