Skip to content

Commit f0354c2

Browse files
committed
fix: resolve module request for ./index should only target app root
1 parent 0ee436a commit f0354c2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cli/metro-server.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ const getDependencyModules = (testAppPath) => {
5151
reactNativeModules: {
5252
corePath: reactNativePath,
5353
initializeCorePath: require.resolve(path.join(reactNativePath, 'Libraries', 'Core', 'InitializeCore')),
54-
cliServerApi: require(path.join(testAppModulesPath, '@react-native-community/cli-server-api')),
54+
cliServerApi: require(path.join(testAppModulesPath, '@react-native-community', 'cli-server-api')),
5555
getPolyfills: require(path.join(reactNativePath, 'rn-get-polyfills')),
5656
},
5757
testAppModulesPath,
5858
};
5959
};
6060

61-
const resolveModule = (moduleName, testAppModulesPath) => {
62-
if (moduleName === './index') {
61+
const resolveModule = (context, moduleName, testAppModulesPath) => {
62+
if (moduleName === './index' && context.originModulePath.endsWith('react-native-test-runner/.')) {
6363
return './app/index';
6464
}
6565

@@ -106,7 +106,7 @@ const getMetroConfig = ({ cwd = process.cwd(), testFileGlobs, port = 8081, testA
106106
resolverMainFields: ['react-native', 'browser', 'main'],
107107
platforms: ['ios', 'android', 'native'],
108108
resolveRequest: (context, realModuleName, platform, moduleName) => {
109-
moduleName = resolveModule(moduleName, testAppModulesPath);
109+
moduleName = resolveModule(context, moduleName, testAppModulesPath);
110110

111111
const originalResolveRequest = context.resolveRequest;
112112

0 commit comments

Comments
 (0)