From 8d44c2db4f62af0fd9382413bb0e0155225b4c64 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Mon, 29 Feb 2016 09:24:19 -0800 Subject: [PATCH] Fix bridge tests Summary:The `RCTDevMenu.hotLoadingAvailable` check always returned YES if `bridge.bundleURL` was nil. This caused the `setHotLoadingEnabled:` method to repeatedly reload the bridge, resulting in the following tests failing: `- [RCTBridgeTests testHookRegistration];` `- [RCTBridgeTests testCallNativeMethod];` Also, the `RUN_RUNLOOP_WHILE()` macro did not actually assert when timing out, and the logic in `- [RCTBridgeTests tearDown];` was broken in such a way that tests would always take 5 seconds to run (and then timeout silently). This adds an assertion, and removes the broken nil check for `jsExecutor`. Reviewed By: majak Differential Revision: D2988885 fb-gh-sync-id: 91307585ac8acb0181f0cddeeddf6cb4b198e4fe shipit-source-id: 91307585ac8acb0181f0cddeeddf6cb4b198e4fe --- Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m | 9 +++++---- React/Modules/RCTDevMenu.m | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m index 31fc8f74e..f415f6da6 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m @@ -24,8 +24,12 @@ #define RUN_RUNLOOP_WHILE(CONDITION) \ { \ NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \ + while ((CONDITION)) { \ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ + if ([timeout timeIntervalSinceNow] <= 0) { \ + XCTFail(@"Runloop timed out before condition was met"); \ + break; \ + } \ } \ } @@ -140,9 +144,6 @@ RCT_EXPORT_MODULE(TestModule) [_bridge invalidate]; _bridge = nil; - - RUN_RUNLOOP_WHILE(_jsExecutor != nil); - XCTAssertNotNil(_jsExecutor); } - (void)testHookRegistration diff --git a/React/Modules/RCTDevMenu.m b/React/Modules/RCTDevMenu.m index 911bddce6..5e1132a21 100644 --- a/React/Modules/RCTDevMenu.m +++ b/React/Modules/RCTDevMenu.m @@ -581,7 +581,7 @@ RCT_EXPORT_METHOD(reload) - (BOOL)hotLoadingAvailable { - return !_bridge.bundleURL.fileURL; // Only works when running from server + return _bridge.bundleURL && !_bridge.bundleURL.fileURL; // Only works when running from server } - (void)setHotLoadingEnabled:(BOOL)enabled