[ReactNative] Unfork RKRootView

This commit is contained in:
Tadeu Zagallo
2015-04-02 07:33:21 -07:00
parent b1e502a083
commit f370f9cbc4
15 changed files with 448 additions and 298 deletions

View File

@@ -21,6 +21,8 @@
// This is used to give meaningful names to snapshot image files.
@property (nonatomic, assign) SEL testSelector;
@property (nonatomic, weak) UIView *view;
- (instancetype)initWithSnapshotController:(FBSnapshotTestController *)controller view:(UIView *)view;
@end

View File

@@ -17,15 +17,6 @@
#define TIMEOUT_SECONDS 240
@interface RCTRootView (Testing)
- (instancetype)_initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
launchOptions:(NSDictionary *)launchOptions
moduleProvider:(RCTBridgeModuleProviderBlock)moduleProvider;
@end
@implementation RCTTestRunner
{
FBSnapshotTestController *_snapshotController;
@@ -75,17 +66,17 @@
RCTTestModule *testModule = [[RCTTestModule alloc] initWithSnapshotController:_snapshotController view:nil];
testModule.testSelector = test;
RCTRootView *rootView = [[RCTRootView alloc] _initWithBundleURL:[NSURL URLWithString:_script]
moduleName:moduleName
launchOptions:nil
moduleProvider:^{
return @[testModule];
}];
[testModule setValue:rootView forKey:@"_view"];
rootView.frame = CGRectMake(0, 0, 320, 2000);
RCTBridge *bridge = [[RCTBridge alloc] initWithBundlePath:_script
moduleProvider:^(){
return @[testModule];
}
launchOptions:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:moduleName];
testModule.view = rootView;
[vc.view addSubview:rootView]; // Add as subview so it doesn't get resized
rootView.initialProperties = initialProps;
rootView.frame = CGRectMake(0, 0, 320, 2000); // Constant size for testing on multiple devices
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
NSString *error = [[RCTRedBox sharedInstance] currentErrorMessage];
@@ -94,8 +85,9 @@
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:date];
error = [[RCTRedBox sharedInstance] currentErrorMessage];
}
[rootView invalidate];
[rootView removeFromSuperview];
[rootView.bridge invalidate];
[rootView invalidate];
RCTAssert(vc.view.subviews.count == 0, @"There shouldn't be any other views: %@", vc.view);
vc.view = nil;
[[RCTRedBox sharedInstance] dismiss];