@@ -14,6 +14,7 @@ const {
1414 configureAppForSwift,
1515 createHardlinks,
1616 findXcodeProjectDirectory,
17+ generateCodegenArtifacts,
1718 runIosPrebuild,
1819 runPodDeintegrate,
1920 setBuildFromSource,
@@ -31,6 +32,9 @@ jest.mock('../headers-utils');
3132// Mock prepare-app-dependencies-headers module
3233jest . mock ( '../prepare-app-dependencies-headers' ) ;
3334
35+ // Mock codegen executor module
36+ jest . mock ( '../../codegen/generate-artifacts-executor' ) ;
37+
3438// Mock path module for absolute paths
3539jest . mock ( 'path' , ( ) => {
3640 const actualPath = jest . requireActual ( 'path' ) ;
@@ -239,6 +243,127 @@ describe('createHardlinks', () => {
239243 } ) ;
240244} ) ;
241245
246+ describe ( 'generateCodegenArtifacts' , ( ) => {
247+ let mockCodegenExecutor ;
248+ let mockConsoleLog ;
249+
250+ beforeEach ( ( ) => {
251+ // Setup mocks
252+ mockCodegenExecutor = require ( '../../codegen/generate-artifacts-executor' ) ;
253+ mockConsoleLog = console . log ;
254+
255+ // Clear and reset all mocks completely
256+ jest . clearAllMocks ( ) ;
257+ jest . resetAllMocks ( ) ;
258+
259+ // Set up fresh mock implementations
260+ mockCodegenExecutor . execute = jest . fn ( ) ;
261+ } ) ;
262+
263+ it ( 'should run codegen successfully' , async ( ) => {
264+ // Setup
265+ const reactNativePath = '/path/to/react-native' ;
266+ const appPath = '/path/to/app' ;
267+ const appIosPath = '/path/to/app/ios' ;
268+
269+ mockCodegenExecutor . execute . mockImplementation ( ( ) => { } ) ;
270+
271+ // Execute
272+ await generateCodegenArtifacts ( reactNativePath , appPath , appIosPath ) ;
273+
274+ // Assert
275+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledWith (
276+ appPath ,
277+ 'ios' ,
278+ appIosPath ,
279+ 'app' ,
280+ ) ;
281+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledTimes ( 1 ) ;
282+
283+ // Verify console output
284+ expect ( mockConsoleLog ) . toHaveBeenCalledWith (
285+ 'Generating codegen artifacts...' ,
286+ ) ;
287+ expect ( mockConsoleLog ) . toHaveBeenCalledWith (
288+ '✓ Codegen artifacts generated' ,
289+ ) ;
290+ } ) ;
291+
292+ it ( 'should throw error when codegen execution fails' , async ( ) => {
293+ // Setup
294+ const reactNativePath = '/path/to/react-native' ;
295+ const appPath = '/path/to/app' ;
296+ const appIosPath = '/path/to/app/ios' ;
297+ const originalError = new Error ( 'Codegen failed to generate artifacts' ) ;
298+
299+ mockCodegenExecutor . execute . mockImplementation ( ( ) => {
300+ throw originalError ;
301+ } ) ;
302+
303+ // Execute & Assert
304+ await expect (
305+ generateCodegenArtifacts ( reactNativePath , appPath , appIosPath ) ,
306+ ) . rejects . toThrow (
307+ 'Codegen generation failed: Codegen failed to generate artifacts' ,
308+ ) ;
309+
310+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledWith (
311+ appPath ,
312+ 'ios' ,
313+ appIosPath ,
314+ 'app' ,
315+ ) ;
316+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledTimes ( 1 ) ;
317+
318+ expect ( mockConsoleLog ) . toHaveBeenCalledWith (
319+ 'Generating codegen artifacts...' ,
320+ ) ;
321+ expect ( mockConsoleLog ) . not . toHaveBeenCalledWith (
322+ '✓ Codegen artifacts generated' ,
323+ ) ;
324+ } ) ;
325+
326+ it ( 'should handle different paths correctly' , async ( ) => {
327+ // Setup
328+ const reactNativePath = '/Users/developer/react-native' ;
329+ const appPath = '/Users/developer/MyApp' ;
330+ const appIosPath = '/Users/developer/MyApp/ios' ;
331+
332+ mockCodegenExecutor . execute . mockImplementation ( ( ) => { } ) ;
333+
334+ // Execute
335+ await generateCodegenArtifacts ( reactNativePath , appPath , appIosPath ) ;
336+
337+ // Assert
338+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledWith (
339+ appPath ,
340+ 'ios' ,
341+ appIosPath ,
342+ 'app' ,
343+ ) ;
344+ } ) ;
345+
346+ it ( 'should handle paths with spaces correctly' , async ( ) => {
347+ // Setup
348+ const reactNativePath = '/path/to/react native' ;
349+ const appPath = '/path/to/my app' ;
350+ const appIosPath = '/path/to/my app/ios folder' ;
351+
352+ mockCodegenExecutor . execute . mockImplementation ( ( ) => { } ) ;
353+
354+ // Execute
355+ await generateCodegenArtifacts ( reactNativePath , appPath , appIosPath ) ;
356+
357+ // Assert
358+ expect ( mockCodegenExecutor . execute ) . toHaveBeenCalledWith (
359+ appPath ,
360+ 'ios' ,
361+ appIosPath ,
362+ 'app' ,
363+ ) ;
364+ } ) ;
365+ } ) ;
366+
242367// Mock console methods - disable React Native's strict console checking
243368const originalConsole = global . console ;
244369
0 commit comments