Files
react-native/packages/react-native-codegen/e2e/__tests__/modules/GenerateModuleH-test.js
T
Moti Zilberman d6e0bc714a Enable lint/sort-imports everywhere (#41334)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41334

TSIA.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D51025812

fbshipit-source-id: e10d437be775a6b80946483aa96460f34927f870
2023-11-06 12:59:38 -08:00

53 lines
1.5 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';
import type {SchemaType} from '../../../src/CodegenSchema';
const generator = require('../../../src/generators/modules/GenerateModuleH');
const {FlowParser} = require('../../../src/parsers/flow/parser');
const fs = require('fs');
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('GenerateModuleH', () => {
it('can generate a header file NativeModule specs', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), undefined, false);
expect(output.get(libName + 'JSI.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 + 'JSI.h')).toMatchSnapshot();
});
});