Wait for JSExecutor to tear down in RCTBridgeTests
Reviewed By: tadeuzagallo Differential Revision: D2803092 fb-gh-sync-id: 71ccac2c13221bfbcb2f09a14d48ac2d2901d04e
This commit is contained in:
parent
ec76271715
commit
8772a6a542
|
@ -21,6 +21,16 @@
|
|||
#import "RCTJavaScriptExecutor.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
|
||||
#define RUN_RUNLOOP_WHILE(CONDITION) \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
|
||||
NSDate *timeout = [[NSDate date] dateByAddingTimeInterval:0.1]; \
|
||||
while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeout]; \
|
||||
} \
|
||||
_Pragma("clang diagnostic pop")
|
||||
|
||||
@interface TestExecutor : NSObject <RCTJavaScriptExecutor>
|
||||
|
||||
@property (nonatomic, readonly, copy) NSMutableDictionary<NSString *, id> *injectedStuff;
|
||||
|
@ -93,6 +103,8 @@ RCT_EXPORT_MODULE()
|
|||
@interface RCTBridgeTests : XCTestCase <RCTBridgeModule>
|
||||
{
|
||||
RCTBridge *_bridge;
|
||||
__weak TestExecutor *_jsExecutor;
|
||||
|
||||
BOOL _testMethodCalled;
|
||||
}
|
||||
@end
|
||||
|
@ -112,35 +124,34 @@ RCT_EXPORT_MODULE(TestModule)
|
|||
launchOptions:nil];
|
||||
|
||||
_bridge.executorClass = [TestExecutor class];
|
||||
|
||||
// Force to recreate the executor with the new class
|
||||
// - reload: doesn't work here since bridge hasn't loaded yet.
|
||||
[_bridge invalidate];
|
||||
[_bridge setUp];
|
||||
|
||||
_jsExecutor = [_bridge.batchedBridge valueForKey:@"javaScriptExecutor"];
|
||||
XCTAssertNotNil(_jsExecutor);
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[super tearDown];
|
||||
|
||||
[_bridge invalidate];
|
||||
_testMethodCalled = NO;
|
||||
}
|
||||
|
||||
#define RUN_RUNLOOP_WHILE(CONDITION) \
|
||||
_Pragma("clang diagnostic push") \
|
||||
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
|
||||
NSDate *timeout = [[NSDate date] dateByAddingTimeInterval:0.1]; \
|
||||
while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeout]; \
|
||||
} \
|
||||
_Pragma("clang diagnostic pop")
|
||||
[_bridge invalidate];
|
||||
_bridge = nil;
|
||||
|
||||
RUN_RUNLOOP_WHILE(_jsExecutor != nil);
|
||||
XCTAssertNotNil(_jsExecutor);
|
||||
}
|
||||
|
||||
- (void)testHookRegistration
|
||||
{
|
||||
TestExecutor *executor = [_bridge.batchedBridge valueForKey:@"_javaScriptExecutor"];
|
||||
|
||||
NSString *injectedStuff;
|
||||
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));
|
||||
RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"]));
|
||||
XCTAssertNotNil(injectedStuff);
|
||||
|
||||
__block NSNumber *testModuleID = nil;
|
||||
__block NSDictionary<NSString *, id> *testConstants = nil;
|
||||
|
@ -165,10 +176,9 @@ _Pragma("clang diagnostic pop")
|
|||
|
||||
- (void)testCallNativeMethod
|
||||
{
|
||||
TestExecutor *executor = [_bridge.batchedBridge valueForKey:@"_javaScriptExecutor"];
|
||||
|
||||
NSString *injectedStuff;
|
||||
RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"]));
|
||||
RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"]));
|
||||
XCTAssertNotNil(injectedStuff);
|
||||
|
||||
__block NSNumber *testModuleID = nil;
|
||||
__block NSNumber *testMethodID = nil;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#import "RCTTestModule.h"
|
||||
#import "RCTUtils.h"
|
||||
#import "RCTJSCExecutor.h"
|
||||
#import "RCTBridge+Private.h"
|
||||
|
||||
static const NSTimeInterval kTestTimeoutSeconds = 60;
|
||||
static const NSTimeInterval kTestTeardownTimeoutSeconds = 30;
|
||||
|
@ -134,7 +135,7 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
|
|||
|
||||
// Take a weak reference to the JS context, so we track its deallocation later
|
||||
// (we can only do this now, since it's been lazily initialized)
|
||||
id jsExecutor = [bridge valueForKeyPath:@"batchedBridge.javaScriptExecutor"];
|
||||
id jsExecutor = [bridge.batchedBridge valueForKey:@"javaScriptExecutor"];
|
||||
if ([jsExecutor isKindOfClass:[RCTJSCExecutor class]]) {
|
||||
weakJSContext = [jsExecutor valueForKey:@"_context"];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue