Improve DX for FBReactKitIntegrationTests

Summary:
- Enable logging so `console.log` shows up in Xcode console (and CI?)
- Allow loading from bundler for rapid JS iteration.
- Add option to enable JS debugging, although it's a little ghetto.

Reviewed By: mmmulani

Differential Revision: D5869085

fbshipit-source-id: 9c4831859f1491f7f75786f730d8549d69623888
This commit is contained in:
Spencer Ahrens 2017-09-21 18:25:37 -07:00 committed by Facebook Github Bot
parent f7f347329e
commit af2e3fea1b
2 changed files with 25 additions and 8 deletions

View File

@ -50,6 +50,10 @@
*/ */
@property (nonatomic, assign) BOOL recordMode; @property (nonatomic, assign) BOOL recordMode;
@property (nonatomic, assign, readwrite) BOOL useBundler;
@property (nonatomic, assign, readwrite) BOOL useJSDebugger;
@property (nonatomic, copy) NSString *testSuffix; @property (nonatomic, copy) NSString *testSuffix;
@property (nonatomic, readonly) NSURL *scriptURL; @property (nonatomic, readonly) NSURL *scriptURL;

View File

@ -11,6 +11,7 @@
#import <React/RCTAssert.h> #import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h> #import <React/RCTBridge+Private.h>
#import <React/RCTDevSettings.h>
#import <React/RCTLog.h> #import <React/RCTLog.h>
#import <React/RCTRootView.h> #import <React/RCTRootView.h>
#import <React/RCTUtils.h> #import <React/RCTUtils.h>
@ -24,6 +25,7 @@ static const NSTimeInterval kTestTimeoutSeconds = 120;
{ {
FBSnapshotTestController *_testController; FBSnapshotTestController *_testController;
RCTBridgeModuleListProvider _moduleProvider; RCTBridgeModuleListProvider _moduleProvider;
NSString *_appPath;
} }
- (instancetype)initWithApp:(NSString *)app - (instancetype)initWithApp:(NSString *)app
@ -43,19 +45,24 @@ static const NSTimeInterval kTestTimeoutSeconds = 120;
_testController = [[FBSnapshotTestController alloc] initWithTestName:sanitizedAppName]; _testController = [[FBSnapshotTestController alloc] initWithTestName:sanitizedAppName];
_testController.referenceImagesDirectory = referenceDirectory; _testController.referenceImagesDirectory = referenceDirectory;
_moduleProvider = [block copy]; _moduleProvider = [block copy];
_appPath = app;
if (getenv("CI_USE_PACKAGER")) { [self updateScript];
_scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", app]];
} else {
_scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
RCTAssert(_scriptURL != nil, @"No scriptURL set");
} }
return self; return self;
} }
RCT_NOT_IMPLEMENTED(- (instancetype)init) RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (void)updateScript
{
if (getenv("CI_USE_PACKAGER") || _useBundler) {
_scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", _appPath]];
} else {
_scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
RCTAssert(_scriptURL != nil, @"No scriptURL set");
}
- (void)setRecordMode:(BOOL)recordMode - (void)setRecordMode:(BOOL)recordMode
{ {
_testController.recordMode = recordMode; _testController.recordMode = recordMode;
@ -66,6 +73,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
return _testController.recordMode; return _testController.recordMode;
} }
- (void)setUseBundler:(BOOL)useBundler
{
_useBundler = useBundler;
[self updateScript];
}
- (void)runTest:(SEL)test module:(NSString *)moduleName - (void)runTest:(SEL)test module:(NSString *)moduleName
{ {
[self runTest:test module:moduleName initialProps:nil configurationBlock:nil expectErrorBlock:nil]; [self runTest:test module:moduleName initialProps:nil configurationBlock:nil expectErrorBlock:nil];
@ -110,9 +123,9 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_scriptURL RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_scriptURL
moduleProvider:_moduleProvider moduleProvider:_moduleProvider
launchOptions:nil]; launchOptions:nil];
[bridge.devSettings setIsDebuggingRemotely:_useJSDebugger];
batchedBridge = [bridge batchedBridge]; batchedBridge = [bridge batchedBridge];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProps]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProps];
#if TARGET_OS_TV #if TARGET_OS_TV
rootView.frame = CGRectMake(0, 0, 1920, 1080); // Standard screen size for tvOS rootView.frame = CGRectMake(0, 0, 1920, 1080); // Standard screen size for tvOS