Skip to content

Commit

Permalink
Support optional bundle prefix in RNTester integration tests
Browse files Browse the repository at this point in the history
Summary:
Add support for a `CI_USE_BUNDLE_PREFIX` envvar in the RNTester Xcode scheme, as part of ongoing work to enable integration tests in Facebook's internal CI system.

[iOS] [Added] - Add new envvar to support internal iOS tests at Facebook

Reviewed By: cpojer

Differential Revision: D15163397

fbshipit-source-id: 1b75b1868b5f9721a69f6cba4d4052be47e5e5e2
  • Loading branch information
hramos authored and facebook-github-bot committed May 6, 2019
1 parent 28e0de0 commit e94b116
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 5 additions & 1 deletion RNTester/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ - (instancetype)initWithApp:(NSString *)app
- (NSURL *)defaultScriptURL
{
if (getenv("CI_USE_PACKAGER") || _useBundler) {
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", _appPath]];
NSString *bundlePrefix = @"";
if (getenv("CI_USE_BUNDLE_PREFIX")) {
bundlePrefix = @"react-native-github/";
}
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@%@.bundle?platform=ios&dev=true", bundlePrefix, _appPath]];
} else {
return [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "CI_USE_BUNDLE_PREFIX"
value = "0"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
Expand Down
15 changes: 10 additions & 5 deletions RNTester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,29 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith

_bridge = [[RCTBridge alloc] initWithDelegate:self
launchOptions:launchOptions];

// Appetizer.io params check
NSDictionary *initProps = @{};
NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"];
if (_routeUri) {
initProps = @{@"exampleFromAppetizeParams": [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri]};
}

#ifdef RN_FABRIC_ENABLED
// FIXME: remove when resolved https://github.com/facebook/react-native/issues/23910
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleJavaScriptDidLoadNotification:)
name:RCTJavaScriptDidLoadNotification
object:_bridge];

_surfacePresenter = [[RCTSurfacePresenter alloc] initWithBridge:_bridge config:nil];
_bridge.surfacePresenter = _surfacePresenter;

UIView *rootView = [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
#else
UIView *rootView = [[RCTRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
#endif

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
Expand All @@ -109,7 +109,12 @@ - (void)handleJavaScriptDidLoadNotification:(__unused NSNotification*)notificati

- (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
{
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"RNTester/js/RNTesterApp.ios"
NSString *bundlePrefix = @"";
if (getenv("CI_USE_BUNDLE_PREFIX")) {
bundlePrefix = @"react-native-github/";
}
NSString *bundleRoot = [NSString stringWithFormat:@"%@RNTester/js/RNTesterApp.ios", bundlePrefix];
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:bundleRoot
fallbackResource:nil];
}

Expand Down
6 changes: 5 additions & 1 deletion RNTester/RNTesterIntegrationTests/RCTLoggingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ - (void)setUp
{
NSURL *scriptURL;
if (getenv("CI_USE_PACKAGER")) {
NSString *bundlePrefix = @"";
if (getenv("CI_USE_BUNDLE_PREFIX")) {
bundlePrefix = @"react-native-github/";
}
NSString *app = @"IntegrationTests/IntegrationTestsApp";
scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", app]];
scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@%@.bundle?platform=ios&dev=true", bundlePrefix, app]];
} else {
scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
Expand Down

0 comments on commit e94b116

Please sign in to comment.