diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js index 64b911abf1fc17..02133c76f90539 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js @@ -11,85 +11,17 @@ 'use strict'; +const fixtures = require('../__test_fixtures__/fixtures.js'); const generator = require('../GenerateComponentDescriptorH.js'); -const { - ARRAY_PROPS, - BOOLEAN_PROP, - STRING_PROP, - INTEGER_PROPS, - FLOAT_PROPS, - COLOR_PROP, - IMAGE_PROP, - POINT_PROP, - MULTI_NATIVE_PROP, - ENUM_PROP, - EVENT_PROPS, - TWO_COMPONENTS_SAME_FILE, - TWO_COMPONENTS_DIFFERENT_FILES, -} = require('../__test_fixtures__/fixtures.js'); - describe('GenerateComponentDescriptorH', () => { - it('can generate a array props', () => { - expect(generator.generate('ARRAY_PROPS', ARRAY_PROPS)).toMatchSnapshot(); - }); - - it('can generate a single boolean prop', () => { - expect(generator.generate('BOOLEAN_PROP', BOOLEAN_PROP)).toMatchSnapshot(); - }); - - it('can generate a single string prop', () => { - expect(generator.generate('STRING_PROPS', STRING_PROP)).toMatchSnapshot(); - }); - - it('can generate integer props', () => { - expect( - generator.generate('INTEGER_PROPS', INTEGER_PROPS), - ).toMatchSnapshot(); - }); - - it('can generate float props', () => { - expect(generator.generate('FLOAT_PROPS', FLOAT_PROPS)).toMatchSnapshot(); - }); - - it('can generate a single native primitive prop', () => { - expect(generator.generate('COLOR_PROP', COLOR_PROP)).toMatchSnapshot(); - }); - - it('can generate a native primitive image prop', () => { - expect(generator.generate('IMAGE_PROP', IMAGE_PROP)).toMatchSnapshot(); - }); - - it('can generate a native primitive point prop', () => { - expect(generator.generate('IMAGE_PROP', POINT_PROP)).toMatchSnapshot(); - }); - - it('can generate multiple native props', () => { - expect( - generator.generate('MULTI_NATIVE_PROP', MULTI_NATIVE_PROP), - ).toMatchSnapshot(); - }); - - it('can generate enum props', () => { - expect(generator.generate('ENUM_PROP', ENUM_PROP)).toMatchSnapshot(); - }); - - it('can generate events', () => { - expect(generator.generate('EVENT_PROPS', EVENT_PROPS)).toMatchSnapshot(); - }); - - it('supports two components from same module', () => { - expect( - generator.generate('TWO_COMPONENTS_SAME_FILE', TWO_COMPONENTS_SAME_FILE), - ).toMatchSnapshot(); - }); - - it('supports two components from different modules', () => { - expect( - generator.generate( - 'TWO_COMPONENTS_DIFFERENT_FILES', - TWO_COMPONENTS_DIFFERENT_FILES, - ), - ).toMatchSnapshot(); - }); + Object.keys(fixtures) + .sort() + .forEach(fixtureName => { + const fixture = fixtures[fixtureName]; + + it(`can generate fixture ${fixtureName}`, () => { + expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + }); + }); }); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap index 6a46dea5fb24e6..2ad02997bd5183 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`GenerateComponentDescriptorH can generate a array props 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture ARRAY_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -26,7 +26,7 @@ using ArrayPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor } `; -exports[`GenerateComponentDescriptorH can generate a native primitive image prop 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture BOOLEAN_PROP 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -38,13 +38,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using ImagePropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using BooleanPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -52,7 +52,7 @@ using ImagePropNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; -exports[`GenerateComponentDescriptorH can generate a native primitive point prop 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture COLOR_PROP 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -64,13 +64,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using PointPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using ColorPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -78,7 +78,7 @@ using PointPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; -exports[`GenerateComponentDescriptorH can generate a single boolean prop 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture COMMANDS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -90,13 +90,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using BooleanPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using CommandNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -104,7 +104,7 @@ using BooleanPropNativeComponentComponentDescriptor = ConcreteComponentDescripto } `; -exports[`GenerateComponentDescriptorH can generate a single native primitive prop 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture COMMANDS_AND_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -116,13 +116,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using ColorPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using CommandNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -130,7 +130,7 @@ using ColorPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; -exports[`GenerateComponentDescriptorH can generate a single string prop 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture ENUM_PROP 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -142,13 +142,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using StringPropComponentComponentDescriptor = ConcreteComponentDescriptor; +using EnumPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -156,7 +156,7 @@ using StringPropComponentComponentDescriptor = ConcreteComponentDescriptor " /** @@ -168,13 +168,13 @@ Map { #pragma once -#include +#include #include namespace facebook { namespace react { -using EnumPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using EventsNestedObjectNativeComponentComponentDescriptor = ConcreteComponentDescriptor; } // namespace react } // namespace facebook @@ -182,7 +182,7 @@ using EnumPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; -exports[`GenerateComponentDescriptorH can generate events 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture EVENT_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -208,7 +208,33 @@ using EventsNativeComponentComponentDescriptor = ConcreteComponentDescriptor " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture FLOAT_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -234,7 +260,33 @@ using FloatPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; -exports[`GenerateComponentDescriptorH can generate integer props 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture IMAGE_PROP 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using ImagePropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture INTEGER_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -260,7 +312,33 @@ using IntegerPropNativeComponentComponentDescriptor = ConcreteComponentDescripto } `; -exports[`GenerateComponentDescriptorH can generate multiple native props 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture INTERFACE_ONLY 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture MULTI_NATIVE_PROP 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -286,7 +364,85 @@ using ImageColorPropNativeComponentComponentDescriptor = ConcreteComponentDescri } `; -exports[`GenerateComponentDescriptorH supports two components from different modules 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture NO_PROPS_NO_EVENTS 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using NoPropsNoEventsComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture POINT_PROP 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using PointPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture STRING_PROP 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using StringPropComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateComponentDescriptorH can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` Map { "ComponentDescriptors.h" => " /** @@ -313,7 +469,7 @@ using MultiFile2NativeComponentComponentDescriptor = ConcreteComponentDescriptor } `; -exports[`GenerateComponentDescriptorH supports two components from same module 1`] = ` +exports[`GenerateComponentDescriptorH can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = ` Map { "ComponentDescriptors.h" => " /**