diff --git a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js index 9c19157e3a5..fa51aebd281 100644 --- a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js +++ b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js @@ -507,3 +507,41 @@ describe('findFilesWithExtension', () => { ]); }); }); + +describe('generateSchemaInfos', () => { + beforeEach(() => { + jest.resetModules(); + }); + + it('forwards the platform (not the array map index) to combineSchemasInFileList', () => { + const mockCombineSchemasInFileList = jest.fn( + (_files: ReadonlyArray, _platform: string) => ({}), + ); + jest.mock('../codegen-utils', () => ({ + getCombineJSToSchema: () => ({ + combineSchemasInFileList: mockCombineSchemasInFileList, + }), + })); + // Avoid touching the filesystem for podspec discovery. + jest.mock('tinyglobby', () => ({globSync: () => []})); + + const { + generateSchemaInfos, + } = require('../generate-artifacts-executor/generateSchemaInfos'); + + const libraries = [ + {config: {name: 'LibA', jsSrcsDir: 'src'}, libraryPath: '/tmp/libA'}, + {config: {name: 'LibB', jsSrcsDir: 'src'}, libraryPath: '/tmp/libB'}, + ]; + + generateSchemaInfos(libraries, 'ios'); + + // Regression guard: previously `libraries.map(generateSchemaInfo)` handed the + // array index to generateSchemaInfo as the platform. Every call must receive + // the real platform string instead. + expect(mockCombineSchemasInFileList).toHaveBeenCalledTimes(2); + for (const call of mockCombineSchemasInFileList.mock.calls) { + expect(call[1]).toBe('ios'); + } + }); +}); diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js index 0b053103b91..64186454841 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js @@ -18,9 +18,10 @@ const {globSync} = require('tinyglobby'); function generateSchemaInfos( libraries /*: ReadonlyArray<$FlowFixMe> */, + platform /*: string */, ) /*: Array<$FlowFixMe> */ { // $FlowFixMe[incompatible-type] - return libraries.map(generateSchemaInfo); + return libraries.map(library => generateSchemaInfo(library, platform)); } function generateSchemaInfo( diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index 7ce38a55a88..553af035a48 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -139,7 +139,7 @@ function execute( : path.join(outputPath, 'ReactCodegen'); if (runReactNativeCodegen) { - const schemaInfos = generateSchemaInfos(libraries); + const schemaInfos = generateSchemaInfos(libraries, platform); generateNativeCode( reactCodegenOutputPath, schemaInfos.filter(schemaInfo =>