|
11 | 11 | 'use strict'; |
12 | 12 |
|
13 | 13 | const { |
| 14 | + symlinkCodegenHeaders, |
14 | 15 | symlinkHeadersFromPath, |
15 | 16 | symlinkReactAppleHeaders, |
16 | 17 | symlinkReactCommonHeaders, |
@@ -44,7 +45,8 @@ describe('symlinkHeadersFromPath', () => { |
44 | 45 | mockPath.dirname.mockImplementation(filePath => { |
45 | 46 | const parts = filePath.split('/'); |
46 | 47 | parts.pop(); |
47 | | - return parts.join('/'); |
| 48 | + const result = parts.join('/'); |
| 49 | + return result === '' ? '.' : result; |
48 | 50 | }); |
49 | 51 | mockPath.basename.mockImplementation(filePath => { |
50 | 52 | return filePath.split('/').pop(); |
@@ -295,6 +297,169 @@ describe('symlinkHeadersFromPath', () => { |
295 | 297 | }); |
296 | 298 | }); |
297 | 299 |
|
| 300 | +describe('symlinkCodegenHeaders', () => { |
| 301 | + let mockUtils; |
| 302 | + let mockFs; |
| 303 | + let mockPath; |
| 304 | + let originalConsoleWarn; |
| 305 | + let originalConsoleLog; |
| 306 | + |
| 307 | + beforeEach(() => { |
| 308 | + // Setup mocks |
| 309 | + mockUtils = require('../utils'); |
| 310 | + mockFs = require('fs'); |
| 311 | + mockPath = require('path'); |
| 312 | + |
| 313 | + // Mock path functions |
| 314 | + mockPath.relative.mockImplementation((from, to) => { |
| 315 | + return to.replace(from + '/', ''); |
| 316 | + }); |
| 317 | + mockPath.join.mockImplementation((...args) => args.join('/')); |
| 318 | + mockPath.dirname.mockImplementation(filePath => { |
| 319 | + const parts = filePath.split('/'); |
| 320 | + parts.pop(); |
| 321 | + const result = parts.join('/'); |
| 322 | + return result === '' ? '.' : result; |
| 323 | + }); |
| 324 | + mockPath.basename.mockImplementation(filePath => { |
| 325 | + return filePath.split('/').pop(); |
| 326 | + }); |
| 327 | + |
| 328 | + // Mock console methods to prevent test output noise |
| 329 | + originalConsoleWarn = console.warn; |
| 330 | + originalConsoleLog = console.log; |
| 331 | + console.warn = jest.fn(); |
| 332 | + console.log = jest.fn(); |
| 333 | + |
| 334 | + // Reset all mocks |
| 335 | + jest.clearAllMocks(); |
| 336 | + }); |
| 337 | + |
| 338 | + afterEach(() => { |
| 339 | + // Restore console methods |
| 340 | + console.warn = originalConsoleWarn; |
| 341 | + console.log = originalConsoleLog; |
| 342 | + }); |
| 343 | + |
| 344 | + it('should create symlinks for codegen headers with conditional directory structure', () => { |
| 345 | + // Setup |
| 346 | + const reactNativePath = '/path/to/react-native'; |
| 347 | + const iosAppPath = '/path/to/ios-app'; |
| 348 | + const outputFolder = '/output/folder'; |
| 349 | + const reactCodegenPath = |
| 350 | + '/path/to/ios-app/build/generated/ios/ReactCodegen'; |
| 351 | + const headerFiles = [ |
| 352 | + `${reactCodegenPath}/ComponentDescriptors.h`, |
| 353 | + `${reactCodegenPath}/ModuleProvider.h`, |
| 354 | + `${reactCodegenPath}/react/renderer/components/MyComponent/ComponentDescriptors.h`, |
| 355 | + `${reactCodegenPath}/react/renderer/components/MyComponent/EventEmitter.h`, |
| 356 | + ]; |
| 357 | + |
| 358 | + mockFs.existsSync.mockImplementation(filePath => { |
| 359 | + if (filePath === reactCodegenPath) return true; |
| 360 | + if (filePath.includes('ReactCodegen') && filePath.endsWith('.h')) |
| 361 | + return true; |
| 362 | + return false; |
| 363 | + }); |
| 364 | + mockUtils.listHeadersInFolder.mockReturnValue(headerFiles); |
| 365 | + mockUtils.setupSymlink.mockImplementation(() => {}); |
| 366 | + |
| 367 | + // Execute |
| 368 | + const result = symlinkCodegenHeaders( |
| 369 | + reactNativePath, |
| 370 | + iosAppPath, |
| 371 | + outputFolder, |
| 372 | + ); |
| 373 | + |
| 374 | + // Assert |
| 375 | + expect(mockFs.existsSync).toHaveBeenCalledWith(reactCodegenPath); |
| 376 | + expect(mockUtils.listHeadersInFolder).toHaveBeenCalledWith( |
| 377 | + reactCodegenPath, |
| 378 | + ['headers', 'tests'], |
| 379 | + ); |
| 380 | + // Files with no subpath go to ReactCodegen folder |
| 381 | + expect(mockUtils.setupSymlink).toHaveBeenCalledWith( |
| 382 | + `${reactCodegenPath}/ComponentDescriptors.h`, |
| 383 | + '/output/folder/headers/ReactCodegen/ComponentDescriptors.h', |
| 384 | + ); |
| 385 | + expect(mockUtils.setupSymlink).toHaveBeenCalledWith( |
| 386 | + `${reactCodegenPath}/ModuleProvider.h`, |
| 387 | + '/output/folder/headers/ReactCodegen/ModuleProvider.h', |
| 388 | + ); |
| 389 | + // Files with subpaths preserve structure under headers/ |
| 390 | + expect(mockUtils.setupSymlink).toHaveBeenCalledWith( |
| 391 | + `${reactCodegenPath}/react/renderer/components/MyComponent/ComponentDescriptors.h`, |
| 392 | + '/output/folder/headers/react/renderer/components/MyComponent/ComponentDescriptors.h', |
| 393 | + ); |
| 394 | + expect(mockUtils.setupSymlink).toHaveBeenCalledWith( |
| 395 | + `${reactCodegenPath}/react/renderer/components/MyComponent/EventEmitter.h`, |
| 396 | + '/output/folder/headers/react/renderer/components/MyComponent/EventEmitter.h', |
| 397 | + ); |
| 398 | + expect(result).toBe(4); |
| 399 | + }); |
| 400 | + |
| 401 | + it('should warn and return 0 if ReactCodegen path does not exist', () => { |
| 402 | + // Setup |
| 403 | + const reactNativePath = '/path/to/react-native'; |
| 404 | + const iosAppPath = '/path/to/ios-app'; |
| 405 | + const outputFolder = '/output/folder'; |
| 406 | + const reactCodegenPath = |
| 407 | + '/path/to/ios-app/build/generated/ios/ReactCodegen'; |
| 408 | + |
| 409 | + mockFs.existsSync.mockImplementation(filePath => { |
| 410 | + if (filePath === reactCodegenPath) return false; // ReactCodegen path doesn't exist |
| 411 | + return false; |
| 412 | + }); |
| 413 | + |
| 414 | + // Execute |
| 415 | + const result = symlinkCodegenHeaders( |
| 416 | + reactNativePath, |
| 417 | + iosAppPath, |
| 418 | + outputFolder, |
| 419 | + ); |
| 420 | + |
| 421 | + // Assert |
| 422 | + expect(console.warn).toHaveBeenCalledWith( |
| 423 | + `ReactCodegen path does not exist: ${reactCodegenPath}`, |
| 424 | + ); |
| 425 | + expect(mockUtils.listHeadersInFolder).not.toHaveBeenCalled(); |
| 426 | + expect(result).toBe(0); |
| 427 | + }); |
| 428 | + |
| 429 | + it('should return 0 if no header files exist', () => { |
| 430 | + // Setup |
| 431 | + const reactNativePath = '/path/to/react-native'; |
| 432 | + const iosAppPath = '/path/to/ios-app'; |
| 433 | + const outputFolder = '/output/folder'; |
| 434 | + const reactCodegenPath = |
| 435 | + '/path/to/ios-app/build/generated/ios/ReactCodegen'; |
| 436 | + |
| 437 | + mockFs.existsSync.mockImplementation(filePath => { |
| 438 | + if (filePath === reactCodegenPath) return true; |
| 439 | + return false; |
| 440 | + }); |
| 441 | + mockUtils.listHeadersInFolder.mockReturnValue([]); |
| 442 | + |
| 443 | + // Execute |
| 444 | + const result = symlinkCodegenHeaders( |
| 445 | + reactNativePath, |
| 446 | + iosAppPath, |
| 447 | + outputFolder, |
| 448 | + ); |
| 449 | + |
| 450 | + // Assert |
| 451 | + expect(mockUtils.listHeadersInFolder).toHaveBeenCalledWith( |
| 452 | + reactCodegenPath, |
| 453 | + ['headers', 'tests'], |
| 454 | + ); |
| 455 | + expect(mockUtils.setupSymlink).not.toHaveBeenCalled(); |
| 456 | + expect(console.log).toHaveBeenCalledWith( |
| 457 | + 'Created symlinks for 0 Codegen headers with conditional directory structure', |
| 458 | + ); |
| 459 | + expect(result).toBe(0); |
| 460 | + }); |
| 461 | +}); |
| 462 | + |
298 | 463 | describe('symlinkThirdPartyDependenciesHeaders', () => { |
299 | 464 | let mockUtils; |
300 | 465 | let mockFs; |
|
0 commit comments