Skip to content

Commit

Permalink
fix: resolve module request for ./index should only target app root
Browse files Browse the repository at this point in the history
  • Loading branch information
acostalima committed Jan 11, 2021
1 parent 0ee436a commit f0354c2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cli/metro-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ const getDependencyModules = (testAppPath) => {
reactNativeModules: {
corePath: reactNativePath,
initializeCorePath: require.resolve(path.join(reactNativePath, 'Libraries', 'Core', 'InitializeCore')),
cliServerApi: require(path.join(testAppModulesPath, '@react-native-community/cli-server-api')),
cliServerApi: require(path.join(testAppModulesPath, '@react-native-community', 'cli-server-api')),
getPolyfills: require(path.join(reactNativePath, 'rn-get-polyfills')),
},
testAppModulesPath,
};
};

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

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

const originalResolveRequest = context.resolveRequest;

Expand Down

0 comments on commit f0354c2

Please sign in to comment.