Files
react-native/packages/react-native-codegen/e2e/__tests__/modules/GenerateModuleObjCpp-test.js
T
MaeIg 3f2691cf84 Extract the parseFile function in the typescript and flow parsers (#35318)
Summary:
This PR aims to extract  the parseFile function in the typescript and flow parsers.  This is to solve the problem described [here](https://github.com/facebook/react-native/pull/35158#issuecomment-1298330753) and help with the work done in https://github.com/facebook/react-native/issues/34872.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the parseFile function in the typescript and flow parsers

Pull Request resolved: https://github.com/facebook/react-native/pull/35318

Test Plan:
yarn flow:
<img width="496" alt="image" src="https://user-images.githubusercontent.com/40902940/206518024-83084c3d-ab0d-4a04-810a-d40270add4b0.png">

yarn lint:
<img width="495" alt="image" src="https://user-images.githubusercontent.com/40902940/206518076-9e07eafe-db61-4c6e-8aaa-f92f190cf4f3.png">

yarn test:
<img width="389" alt="image" src="https://user-images.githubusercontent.com/40902940/206518118-5633b28c-b79b-4421-80f7-de1e03fb8ff2.png">

Reviewed By: cortinico

Differential Revision: D41248581

Pulled By: cipolleschi

fbshipit-source-id: f5b878a28a7de612fcdd1528f064b44f668503af
2022-12-13 09:00:46 -08:00

59 lines
1.8 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
'use strict';
const {FlowParser} = require('../../../src/parsers/flow/parser');
const generator = require('../../../src/generators/modules/GenerateModuleObjCpp');
const fs = require('fs');
import type {SchemaType} from '../../../src/CodegenSchema';
const FIXTURE_DIR = `${__dirname}/../../__test_fixtures__/modules`;
const parser = new FlowParser();
function getModules(): SchemaType {
const filenames: Array<string> = fs.readdirSync(FIXTURE_DIR);
return filenames.reduce<SchemaType>(
(accumulator, file) => {
const schema = parser.parseFile(`${FIXTURE_DIR}/${file}`);
return {
modules: {
...accumulator.modules,
...schema.modules,
},
};
},
{modules: {}},
);
}
describe('GenerateModuleObjCpp', () => {
it('can generate a header file NativeModule specs', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), undefined, false);
expect(output.get(libName + '.h')).toMatchSnapshot();
});
it('can generate a header file NativeModule specs with assume nonnull enabled', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), undefined, true);
expect(output.get(libName + '.h')).toMatchSnapshot();
});
it('can generate an implementation file NativeModule specs', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), undefined, false);
expect(output.get(libName + '-generated.mm')).toMatchSnapshot();
});
});