Permalink
Browse files

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
  • Loading branch information...
sahrens authored and facebook-github-bot committed Sep 22, 2017
1 parent f7f3473 commit af2e3fea1b6782aa652b79de51a250944fc7b0ff
Showing with 25 additions and 8 deletions.
  1. +4 −0 Libraries/RCTTest/RCTTestRunner.h
  2. +21 −8 Libraries/RCTTest/RCTTestRunner.m
@@ -50,6 +50,10 @@
*/
@property (nonatomic, assign) BOOL recordMode;
@property (nonatomic, assign, readwrite) BOOL useBundler;
@property (nonatomic, assign, readwrite) BOOL useJSDebugger;
@property (nonatomic, copy) NSString *testSuffix;
@property (nonatomic, readonly) NSURL *scriptURL;
@@ -11,6 +11,7 @@
#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTDevSettings.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#import <React/RCTUtils.h>
@@ -24,6 +25,7 @@ @implementation RCTTestRunner
{
FBSnapshotTestController *_testController;
RCTBridgeModuleListProvider _moduleProvider;
NSString *_appPath;
}
- (instancetype)initWithApp:(NSString *)app
@@ -43,19 +45,24 @@ - (instancetype)initWithApp:(NSString *)app
_testController = [[FBSnapshotTestController alloc] initWithTestName:sanitizedAppName];
_testController.referenceImagesDirectory = referenceDirectory;
_moduleProvider = [block copy];
if (getenv("CI_USE_PACKAGER")) {
_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");
_appPath = app;
[self updateScript];
}
return self;
}
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
{
_testController.recordMode = recordMode;
@@ -66,6 +73,12 @@ - (BOOL)recordMode
return _testController.recordMode;
}
- (void)setUseBundler:(BOOL)useBundler
{
_useBundler = useBundler;
[self updateScript];
}
- (void)runTest:(SEL)test module:(NSString *)moduleName
{
[self runTest:test module:moduleName initialProps:nil configurationBlock:nil expectErrorBlock:nil];
@@ -110,9 +123,9 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:_scriptURL
moduleProvider:_moduleProvider
launchOptions:nil];
[bridge.devSettings setIsDebuggingRemotely:_useJSDebugger];
batchedBridge = [bridge batchedBridge];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProps];
#if TARGET_OS_TV
rootView.frame = CGRectMake(0, 0, 1920, 1080); // Standard screen size for tvOS

0 comments on commit af2e3fe

Please sign in to comment.