|
10 | 10 |
|
11 | 11 | 'use strict'; |
12 | 12 |
|
13 | | -const {findXcodeProjectDirectory} = require('../prepare-app-utils'); |
| 13 | +const { |
| 14 | + findXcodeProjectDirectory, |
| 15 | + runPodDeintegrate, |
| 16 | +} = require('../prepare-app-utils'); |
14 | 17 |
|
15 | 18 | // Mock child_process module |
16 | 19 | jest.mock('child_process'); |
17 | 20 |
|
| 21 | +// Mock console methods - disable React Native's strict console checking |
| 22 | +const originalConsole = global.console; |
| 23 | + |
| 24 | +beforeAll(() => { |
| 25 | + global.console = { |
| 26 | + ...originalConsole, |
| 27 | + log: jest.fn(), |
| 28 | + warn: jest.fn(), |
| 29 | + }; |
| 30 | +}); |
| 31 | + |
| 32 | +afterAll(() => { |
| 33 | + global.console = originalConsole; |
| 34 | +}); |
| 35 | + |
18 | 36 | describe('findXcodeProjectDirectory', () => { |
19 | 37 | let mockExecSync; |
20 | 38 |
|
@@ -155,3 +173,138 @@ describe('findXcodeProjectDirectory', () => { |
155 | 173 | ); |
156 | 174 | }); |
157 | 175 | }); |
| 176 | + |
| 177 | +describe('runPodDeintegrate', () => { |
| 178 | + let mockExecSync; |
| 179 | + let mockConsoleLog; |
| 180 | + let mockConsoleWarn; |
| 181 | + |
| 182 | + beforeEach(() => { |
| 183 | + // Setup mocks |
| 184 | + const childProcess = require('child_process'); |
| 185 | + mockExecSync = childProcess.execSync; |
| 186 | + |
| 187 | + mockConsoleLog = console.log; |
| 188 | + mockConsoleWarn = console.warn; |
| 189 | + |
| 190 | + // Reset all mocks |
| 191 | + jest.clearAllMocks(); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should run pod deintegrate successfully', async () => { |
| 195 | + // Setup |
| 196 | + const appIosPath = '/path/to/app/ios'; |
| 197 | + |
| 198 | + mockExecSync.mockReturnValue(undefined); |
| 199 | + |
| 200 | + // Execute |
| 201 | + await runPodDeintegrate(appIosPath); |
| 202 | + |
| 203 | + // Assert |
| 204 | + expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', { |
| 205 | + cwd: appIosPath, |
| 206 | + stdio: 'inherit', |
| 207 | + }); |
| 208 | + expect(mockExecSync).toHaveBeenCalledTimes(1); |
| 209 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 210 | + 'Running pod deintegrate in: /path/to/app/ios', |
| 211 | + ); |
| 212 | + expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed'); |
| 213 | + expect(mockConsoleLog).toHaveBeenCalledTimes(2); |
| 214 | + expect(mockConsoleWarn).not.toHaveBeenCalled(); |
| 215 | + }); |
| 216 | + |
| 217 | + it('should handle different iOS directory paths', async () => { |
| 218 | + // Setup |
| 219 | + const appIosPath = '/Users/developer/MyApp/ios'; |
| 220 | + |
| 221 | + mockExecSync.mockReturnValue(undefined); |
| 222 | + |
| 223 | + // Execute |
| 224 | + await runPodDeintegrate(appIosPath); |
| 225 | + |
| 226 | + // Assert |
| 227 | + expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', { |
| 228 | + cwd: appIosPath, |
| 229 | + stdio: 'inherit', |
| 230 | + }); |
| 231 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 232 | + 'Running pod deintegrate in: /Users/developer/MyApp/ios', |
| 233 | + ); |
| 234 | + expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed'); |
| 235 | + }); |
| 236 | + |
| 237 | + it('should handle paths with spaces correctly', async () => { |
| 238 | + // Setup |
| 239 | + const appIosPath = '/path/to/my app/ios folder'; |
| 240 | + |
| 241 | + mockExecSync.mockReturnValue(undefined); |
| 242 | + |
| 243 | + // Execute |
| 244 | + await runPodDeintegrate(appIosPath); |
| 245 | + |
| 246 | + // Assert |
| 247 | + expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', { |
| 248 | + cwd: appIosPath, |
| 249 | + stdio: 'inherit', |
| 250 | + }); |
| 251 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 252 | + 'Running pod deintegrate in: /path/to/my app/ios folder', |
| 253 | + ); |
| 254 | + expect(mockConsoleLog).toHaveBeenCalledWith('✓ Pod deintegrate completed'); |
| 255 | + }); |
| 256 | + |
| 257 | + it('should handle pod deintegrate command failure gracefully', async () => { |
| 258 | + // Setup |
| 259 | + const appIosPath = '/path/to/app/ios'; |
| 260 | + const mockError = new Error('No Podfile.lock found'); |
| 261 | + |
| 262 | + mockExecSync.mockImplementation(() => { |
| 263 | + throw mockError; |
| 264 | + }); |
| 265 | + |
| 266 | + // Execute |
| 267 | + await runPodDeintegrate(appIosPath); |
| 268 | + |
| 269 | + // Assert |
| 270 | + expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', { |
| 271 | + cwd: appIosPath, |
| 272 | + stdio: 'inherit', |
| 273 | + }); |
| 274 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 275 | + 'Running pod deintegrate in: /path/to/app/ios', |
| 276 | + ); |
| 277 | + expect(mockConsoleLog).not.toHaveBeenCalledWith( |
| 278 | + '✓ Pod deintegrate completed', |
| 279 | + ); |
| 280 | + expect(mockConsoleWarn).toHaveBeenCalledWith( |
| 281 | + '⚠️ Pod deintegrate failed (this might be expected if no Podfile.lock exists)', |
| 282 | + ); |
| 283 | + expect(mockConsoleWarn).toHaveBeenCalledTimes(1); |
| 284 | + }); |
| 285 | + |
| 286 | + it('should handle command not found error', async () => { |
| 287 | + // Setup |
| 288 | + const appIosPath = '/path/to/app/ios'; |
| 289 | + const mockError = new Error('command not found: pod'); |
| 290 | + |
| 291 | + mockExecSync.mockImplementation(() => { |
| 292 | + throw mockError; |
| 293 | + }); |
| 294 | + |
| 295 | + // Execute |
| 296 | + await runPodDeintegrate(appIosPath); |
| 297 | + |
| 298 | + // Assert |
| 299 | + expect(mockExecSync).toHaveBeenCalledWith('pod deintegrate', { |
| 300 | + cwd: appIosPath, |
| 301 | + stdio: 'inherit', |
| 302 | + }); |
| 303 | + expect(mockConsoleLog).toHaveBeenCalledWith( |
| 304 | + 'Running pod deintegrate in: /path/to/app/ios', |
| 305 | + ); |
| 306 | + expect(mockConsoleWarn).toHaveBeenCalledWith( |
| 307 | + '⚠️ Pod deintegrate failed (this might be expected if no Podfile.lock exists)', |
| 308 | + ); |
| 309 | + }); |
| 310 | +}); |
0 commit comments