mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e4d0153a67
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
91 lines
2.7 KiB
JavaScript
91 lines
2.7 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
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const sut = require('../generate-specs-cli-executor');
|
|
const fixtures = require('../__test_fixtures__/fixtures');
|
|
const path = require('path');
|
|
|
|
describe('generateSpec', () => {
|
|
it('invokes RNCodegen with the right params', () => {
|
|
const platform = 'ios';
|
|
const libraryType = 'all';
|
|
const schemaPath = './';
|
|
const componentsOutputDir = path.normalize(
|
|
'app/ios/build/generated/ios/react/renderer/components/library',
|
|
);
|
|
const modulesOutputDir = path.normalize(
|
|
'app/ios/build/generated/ios/library',
|
|
);
|
|
const outputDirectory = path.normalize('app/ios/build/generated/ios');
|
|
const libraryName = 'library';
|
|
const packageName = 'com.library';
|
|
const generators = ['componentsIOS', 'modulesIOS'];
|
|
|
|
jest.mock('fs', () => ({
|
|
readFileSync: (path, encoding) => {
|
|
expect(path).toBe(schemaPath);
|
|
expect(encoding).toBe('utf-8');
|
|
return fixtures.schemaText;
|
|
},
|
|
}));
|
|
|
|
let mkdirpSyncInvoked = 0;
|
|
jest.mock('mkdirp', () => ({
|
|
sync: folder => {
|
|
if (mkdirpSyncInvoked === 0) {
|
|
expect(folder).toBe(outputDirectory);
|
|
}
|
|
|
|
if (mkdirpSyncInvoked === 1) {
|
|
expect(folder).toBe(componentsOutputDir);
|
|
}
|
|
|
|
if (mkdirpSyncInvoked === 2) {
|
|
expect(folder).toBe(modulesOutputDir);
|
|
}
|
|
|
|
mkdirpSyncInvoked += 1;
|
|
},
|
|
}));
|
|
|
|
// We cannot mock directly the `RNCodegen` object because the
|
|
// code access the `lib` folder directly and request a file explicitly.
|
|
// This makes testing harder than usually. To overcome this, we created a utility
|
|
// to retrieve the `Codegen`. By doing that, we can mock the wrapper so that it returns
|
|
// an object with the same interface of the `RNCodegen` object.
|
|
jest.mock('../codegen-utils', () => ({
|
|
getCodegen: () => ({
|
|
generate: (libraryConfig, generatorConfigs) => {
|
|
expect(libraryConfig.libraryName).toBe(libraryName);
|
|
expect(libraryConfig.schema).toStrictEqual(fixtures.schema);
|
|
expect(libraryConfig.outputDirectory).toBe(outputDirectory);
|
|
expect(libraryConfig.packageName).toBe(packageName);
|
|
|
|
expect(generatorConfigs.generators).toStrictEqual(generators);
|
|
expect(generatorConfigs.test).toBeUndefined();
|
|
},
|
|
}),
|
|
}));
|
|
|
|
sut.execute(
|
|
platform,
|
|
schemaPath,
|
|
outputDirectory,
|
|
libraryName,
|
|
packageName,
|
|
libraryType,
|
|
);
|
|
|
|
expect(mkdirpSyncInvoked).toBe(3);
|
|
});
|
|
});
|