Skip to content

Commit 857137d

Browse files
RSNarafacebook-github-bot
authored andcommitted
Create E2E tests for Component Generators
Summary: ## Rationale - We actually don't have E2E tests that test the parser + generator together, until now. - **Documentation Value:** These tests show how the Component Spec files in [react-native-codegen/e2e/__test_fixtures__/](https://www.internalfb.com/code/fbsource/[e32a790dfa05]/xplat/js/react-native-github/packages/react-native-codegen/e2e/__test_fixtures__/components/) map to all the different types of codegen output. Changelog: [Internal] Reviewed By: sshic Differential Revision: D32081445 fbshipit-source-id: 02cd17945ef63a42381d6d4adbd0a9b0eaa2a1ef
1 parent cfacfe8 commit 857137d

24 files changed

+6182
-7
lines changed

packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
* @flow strict-local
99
*/
1010

11-
import type {
12-
PointValue,
13-
EdgeInsetsValue,
14-
} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
11+
import type {PointValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
1512
import type {ColorValue} from '../../../../../Libraries/StyleSheet/StyleSheet';
1613
import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
1714
import type {
@@ -34,7 +31,8 @@ type NativeProps = $ReadOnly<{|
3431
colors?: $ReadOnlyArray<ColorValue>,
3532
srcs?: $ReadOnlyArray<ImageSource>,
3633
points?: $ReadOnlyArray<PointValue>,
37-
edgeInsets?: $ReadOnlyArray<EdgeInsetsValue>,
34+
// TODO(T104760003) Fix EdgeInsetsValue in codegen
35+
// edgeInsets?: $ReadOnlyArray<EdgeInsetsValue>,
3836
sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>,
3937
object?: $ReadOnlyArray<$ReadOnly<{|prop: string|}>>,
4038
|}>;

packages/react-native-codegen/e2e/__test_fixtures__/components/EdgeInsetsPropNativeComponent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @flow strict-local
99
*/
1010

11-
import type {EdgeInsetsValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
1211
import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
1312
import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
1413
import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
@@ -17,7 +16,8 @@ type NativeProps = $ReadOnly<{|
1716
...ViewProps,
1817

1918
// Props
20-
contentInset?: EdgeInsetsValue,
19+
// TODO(T104760003) Fix EdgeInsetsValue in codegen
20+
// contentInset?: EdgeInsetsValue,
2121
|}>;
2222

2323
export default (codegenNativeComponent<NativeProps>(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GenerateComponentDescriptorH');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GenerateComponentDescriptorH can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GenerateComponentHObjCpp');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GenerateComponentHObjCpp can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GenerateEventEmitterCpp');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GenerateEventEmitterCpp can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GenerateEventEmitterH');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GenerateEventEmitterH can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GeneratePropsCpp');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GeneratePropsCpp can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GeneratePropsH');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GeneratePropsH can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GeneratePropsJavaDelegate');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
20+
const fixtures = fs.readdirSync(FIXTURE_DIR);
21+
22+
fixtures.forEach(fixture => {
23+
it(`GeneratePropsJavaDelegate can generate for '${fixture}'`, () => {
24+
const libName = 'RNCodegenModuleFixtures';
25+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
26+
const output = generator.generate(libName, schema);
27+
expect(Object.fromEntries(output)).toMatchSnapshot();
28+
});
29+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+react_native
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
const parser = require('../../../src/parsers/flow');
15+
const generator = require('../../../src/generators/components/GeneratePropsJavaInterface');
16+
const fs = require('fs');
17+
18+
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/components`;
19+
const fixtures = fs.readdirSync(FIXTURE_DIR);
20+
21+
fixtures.forEach(fixture => {
22+
it(`GeneratePropsJavaInterface can generate for '${fixture}'`, () => {
23+
const libName = 'RNCodegenModuleFixtures';
24+
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
25+
const output = generator.generate(libName, schema, undefined, false);
26+
expect(Object.fromEntries(output)).toMatchSnapshot();
27+
});
28+
});

0 commit comments

Comments
 (0)