mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 20:01:01 +08:00
Wait for bridge to disappear when running tests
Reviewed By: fkgozali Differential Revision: D5592347 fbshipit-source-id: c9a672f2d79c8656b72f585aac7c6f5fec6e72b0
This commit is contained in:
committed by
Facebook Github Bot
parent
b78b8cc9e7
commit
b1bb0a71d5
@@ -10,6 +10,7 @@
|
||||
#import "RCTTestRunner.h"
|
||||
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTBridge+Private.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTRootView.h>
|
||||
#import <React/RCTUtils.h>
|
||||
@@ -94,20 +95,23 @@ expectErrorRegex:(NSString *)errorRegex
|
||||
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
|
||||
expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
|
||||
{
|
||||
__weak RCTBridge *batchedBridge;
|
||||
|
||||
@autoreleasepool {
|
||||
__block NSString *error = nil;
|
||||
RCTLogFunction defaultLogFunction = RCTGetLogFunction();
|
||||
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
|
||||
defaultLogFunction(level, source, fileName, lineNumber, message);
|
||||
if (level >= RCTLogLevelError) {
|
||||
error = message;
|
||||
} else {
|
||||
defaultLogFunction(level, source, fileName, lineNumber, message);
|
||||
}
|
||||
});
|
||||
|
||||
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_scriptURL
|
||||
moduleProvider:_moduleProvider
|
||||
launchOptions:nil];
|
||||
batchedBridge = [bridge batchedBridge];
|
||||
|
||||
|
||||
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProps];
|
||||
#if TARGET_OS_TV
|
||||
@@ -156,8 +160,17 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
|
||||
RCTAssert(testModule.status != RCTTestStatusPending, @"Test didn't finish within %0.f seconds", kTestTimeoutSeconds);
|
||||
RCTAssert(testModule.status == RCTTestStatusPassed, @"Test failed");
|
||||
}
|
||||
|
||||
[bridge invalidate];
|
||||
}
|
||||
|
||||
// Wait for bridge to disappear before continuing to the next test
|
||||
NSDate *invalidateTimeout = [NSDate dateWithTimeIntervalSinceNow:5];
|
||||
while (invalidateTimeout.timeIntervalSinceNow > 0 && batchedBridge != nil) {
|
||||
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
}
|
||||
RCTAssert(batchedBridge == nil, @"Bridge should be deallocated after the test");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user