Files
react-native/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js
T
Riccardo Cipolleschi e4d0153a67 Update CodeGen to leverage the outputDir as suggested in diff review (#33729)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/33729

This PR addresses [this comment](https://www.internalfb.com/diff/D35820848?dst_version_fbid=496290878846487&transaction_fbid=355967423221044).

It makes the CodeGen to the `outputDir` as base directory for the codegen.

Finally, it updates the unit tests accordingly.

## Changelog
[iOS][Changed] - use `outputDir` as base directory for the codegen and remove the possibility to customize the intermediate path. The generated code requires specific paths in the `#include` directive.

Reviewed By: cortinico, dmitryrykun

Differential Revision: D35935282

fbshipit-source-id: a9ad4e296efb042cf34b20db5eebb59614beb5f6
2022-05-04 04:04:10 -07:00

75 lines
2.0 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.
*
* @emails oncall+react_native
* @flow strict-local
* @format
*/
'use strict';
const rnCodegen = require('../RNCodegen.js');
const fixture = require('../__test_fixtures__/fixtures.js');
const path = require('path');
const outputDirectory = 'tmp/out/';
const packageName = 'na';
describe('RNCodegen.generate', () => {
beforeEach(() => {
jest.resetModules();
});
it('when type `all`, with default paths', () => {
const componentsOutputDir = 'react/renderer/components/library';
const modulesOutputDir = 'library';
const expectedPaths = {
'library.h': modulesOutputDir,
'library-generated.mm': modulesOutputDir,
'ShadowNodes.h': componentsOutputDir,
'ShadowNodes.cpp': componentsOutputDir,
'Props.h': componentsOutputDir,
'Props.cpp': componentsOutputDir,
'RCTComponentViewHelpers.h': componentsOutputDir,
'EventEmitters.h': componentsOutputDir,
'EventEmitters.cpp': componentsOutputDir,
'ComponentDescriptors.h': componentsOutputDir,
};
jest.mock('fs', () => ({
existsSync: location => {
return true;
},
writeFileSync: (location, content) => {
let receivedDir = path.dirname(location);
let receivedBasename = path.basename(location);
let expectedPath = path.join(
outputDirectory,
expectedPaths[receivedBasename],
);
expect(receivedDir).toEqual(expectedPath);
},
}));
const res = rnCodegen.generate(
{
libraryName: 'library',
schema: fixture.all,
outputDirectory: outputDirectory,
packageName: packageName,
assumeNonnull: true,
},
{
generators: ['componentsIOS', 'modulesIOS'],
test: false,
},
);
expect(res).toBeTruthy();
});
});