Skip to content

Commit

Permalink
Use Meta-specific renderers when running tests in Meta infra
Browse files Browse the repository at this point in the history
Summary: Changelog: [internal]

Differential Revision: D66094272
  • Loading branch information
rubennorte authored and facebook-github-bot committed Nov 19, 2024
1 parent 9dfffd8 commit 0dc3e74
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
30 changes: 30 additions & 0 deletions jest/integration/config/hasteImpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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.
*
* @format
*/

'use strict';

const crypto = require('crypto');
const fs = require('fs');

module.exports = {
getHasteName(filePath) {
if (filePath.endsWith('ReactNativeInternalFeatureFlags.js')) {
return 'ReactNativeInternalFeatureFlags';
}

return null;
},

getCacheKey() {
return crypto
.createHash('sha1')
.update(fs.readFileSync(__filename))
.digest('hex');
},
};
15 changes: 12 additions & 3 deletions jest/integration/config/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ const config = {
update: () => {},
},
resolver: {
blockList: null,
sourceExts: [...rnTesterConfig.resolver.sourceExts, 'fb.js'],
blockList: /\/RendererProxy\.fb\.js$/, // Disable dependency injection for the renderer
disableHierarchicalLookup: !!process.env.JS_DIR,
sourceExts: ['fb.js', ...rnTesterConfig.resolver.sourceExts],
nodeModulesPaths: process.env.JS_DIR
? [path.join(process.env.JS_DIR, 'public', 'node_modules')]
: [],
hasteImplModulePath: path.resolve(__dirname, 'hasteImpl.js'),
},
transformer: {
// We need to wrap the default transformer so we can run it from source
// using babel-register.
babelTransformerPath: path.resolve(__dirname, 'metro-babel-transformer.js'),
},
watchFolders: process.env.JS_DIR ? [process.env.JS_DIR] : [],
watchFolders: process.env.JS_DIR
? [
path.join(process.env.JS_DIR, 'RKJSModules', 'vendor', 'react'),
path.join(process.env.JS_DIR, 'tools', 'metro'),
path.join(process.env.JS_DIR, 'node_modules'),
path.join(process.env.JS_DIR, 'public', 'node_modules'),
]
: [],
};

module.exports = mergeConfig(rnTesterConfig, config);
4 changes: 2 additions & 2 deletions jest/integration/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ module.exports = async function runTest(
const setupModulePath = path.resolve(__dirname, '../runtime/setup.js');

const entrypointContents = entrypointTemplate({
testPath: `.${path.sep}${path.relative(BUILD_OUTPUT_PATH, testPath)}`,
setupModulePath: `.${path.sep}${path.relative(BUILD_OUTPUT_PATH, setupModulePath)}`,
testPath: `${path.relative(BUILD_OUTPUT_PATH, testPath)}`,
setupModulePath: `${path.relative(BUILD_OUTPUT_PATH, setupModulePath)}`,
});

const entrypointPath = path.join(
Expand Down
12 changes: 12 additions & 0 deletions jest/integration/runtime/mocks/ReactNativeInternalFeatureFlags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* 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
*/

// Left intentionally empty. All flags are assumed to be false.

0 comments on commit 0dc3e74

Please sign in to comment.