From 7181a00f017d1f81fe4f9cb0e19886f7be4cad5a Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Mon, 2 Nov 2015 13:37:37 -0800 Subject: [PATCH] Fix to make RealmReact tests work in Chrome again Left the RealmReactChromeTests commented out for now until it's confirmed to work in the CI environment. --- .../ios/ReactTestsTests/RealmReactTests.m | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/tests/ReactTests/ios/ReactTestsTests/RealmReactTests.m b/tests/ReactTests/ios/ReactTestsTests/RealmReactTests.m index 70524cac..ad6ede0a 100644 --- a/tests/ReactTests/ios/ReactTestsTests/RealmReactTests.m +++ b/tests/ReactTests/ios/ReactTestsTests/RealmReactTests.m @@ -12,9 +12,6 @@ extern void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSGlobalContextRef ctx, bool includesNativeCallStack); -@interface RCTDevMenu () -@end - @interface RealmReactTests : RealmJSTests @end @@ -23,6 +20,12 @@ extern void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSG @implementation RealmReactTests ++ (void)load { + // We don't want the RCTDevMenu from switching the executor class from underneath us. + IMP init = class_getMethodImplementation([NSObject class], @selector(init)); + class_replaceMethod([RCTDevMenu class], @selector(init), init, NULL); +} + + (Class)executorClass { return NSClassFromString(@"RCTContextExecutor"); } @@ -33,10 +36,7 @@ extern void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSG + (id)currentExecutor { Class executorClass = [self executorClass]; - if (!executorClass) { - NSLog(@"%@: Executor class not found", self); - exit(1); - } + assert(executorClass); static RCTBridge *s_bridge; if (!s_bridge) { @@ -44,20 +44,9 @@ extern void JSGlobalContextSetIncludesNativeCallStackWhenReportingExceptions(JSG } if (!s_bridge.valid) { - NSNotification *notification = [self waitForNotification:RCTDidCreateNativeModules]; - s_bridge = notification.object; - - if (!s_bridge) { - NSLog(@"No RCTBridge provided by RCTJavaScriptDidLoadNotification"); - exit(1); - } - -#ifdef DEBUG - // We don't want the RCTDevMenu from switching the executor class from underneath us. - [s_bridge.devMenu invalidate]; -#endif - - [self waitForNotification:RCTJavaScriptDidLoadNotification]; + NSNotification *notification = [self waitForNotification:RCTJavaScriptDidLoadNotification]; + s_bridge = notification.userInfo[@"bridge"]; + assert(s_bridge); } if (s_bridge.executorClass != executorClass) {