From 3111473d571a8315d11753f8c6acddd2ba301f8f Mon Sep 17 00:00:00 2001 From: Eli White Date: Mon, 28 Oct 2024 12:03:33 -0700 Subject: [PATCH] Add test for native module returning enum (#47229) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47229 Adding a test case for an enum value in a fromNative position Changelog: [Internal] Reviewed By: makovkastar Differential Revision: D65038107 fbshipit-source-id: ed323d9a8b226be3ff571c86fda617cabc17cdb9 --- .../src/generators/modules/__test_fixtures__/fixtures.js | 4 +++- .../src/parsers/flow/modules/__test_fixtures__/fixtures.js | 2 +- .../__snapshots__/module-parser-snapshot-test.js.snap | 4 +++- .../parsers/typescript/modules/__test_fixtures__/fixtures.js | 2 +- .../typescript-module-parser-snapshot-test.js.snap | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js index 6e34e330eff300..a31493780327f8 100644 --- a/packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js @@ -496,7 +496,9 @@ const SIMPLE_NATIVE_MODULES: SchemaType = { typeAnnotation: { type: 'FunctionTypeAnnotation', returnTypeAnnotation: { - type: 'StringTypeAnnotation', + name: 'StringEnum', + type: 'EnumDeclaration', + memberType: 'StringTypeAnnotation', }, params: [ { diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js index 7eb0e0777275ba..1130a84e9b2f6f 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__test_fixtures__/fixtures.js @@ -811,7 +811,7 @@ export type CustomDeviceEvent = { export interface Spec extends TurboModule { +getCallback: () => () => void; +getMixed: (arg: mixed) => mixed; - +getEnums: (quality: Quality, resolution?: Resolution, stringOptions: StringOptions) => string; + +getEnums: (quality: Quality, resolution?: Resolution, stringOptions: StringOptions) => Quality; +getBinaryTreeNode: (arg: BinaryTreeNode) => BinaryTreeNode; +getGraphNode: (arg: GraphNode) => GraphNode; +getMap: (arg: {[a: string]: ?number}) => {[b: string]: ?number}; diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap index 60340fc027f155..0d107690879072 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap @@ -227,7 +227,9 @@ exports[`RN Codegen Flow Parser can generate fixture CXX_ONLY_NATIVE_MODULE 1`] 'typeAnnotation': { 'type': 'FunctionTypeAnnotation', 'returnTypeAnnotation': { - 'type': 'StringTypeAnnotation' + 'name': 'Quality', + 'type': 'EnumDeclaration', + 'memberType': 'StringTypeAnnotation' }, 'params': [ { diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js index 60f5d83fedd513..6927f6c77c65e8 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/fixtures.js @@ -900,7 +900,7 @@ export type CustomDeviceEvent = { export interface Spec extends TurboModule { readonly getCallback: () => () => void; readonly getMixed: (arg: unknown) => unknown; - readonly getEnums: (quality: Quality, resolution?: Resolution, stringOptions: StringOptions) => string; + readonly getEnums: (quality: Quality, resolution?: Resolution, stringOptions: StringOptions) => Quality; readonly getBinaryTreeNode: (arg: BinaryTreeNode) => BinaryTreeNode; readonly getGraphNode: (arg: GraphNode) => GraphNode; readonly getMap: (arg: {[a: string]: number | null;}) => {[b: string]: number | null;}; diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap index 185b5adb7c2395..5ff8fc7f31f00d 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap +++ b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap @@ -218,7 +218,9 @@ exports[`RN Codegen TypeScript Parser can generate fixture CXX_ONLY_NATIVE_MODUL 'typeAnnotation': { 'type': 'FunctionTypeAnnotation', 'returnTypeAnnotation': { - 'type': 'StringTypeAnnotation' + 'name': 'Quality', + 'type': 'EnumDeclaration', + 'memberType': 'StringTypeAnnotation' }, 'params': [ {