Skip to content

Commit

Permalink
Continuous Integration cleanup
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D24700192

fbshipit-source-id: 239a8ad4848a41ad721a635d4ec37d990989f041
  • Loading branch information
cpojer authored and facebook-github-bot committed Nov 5, 2020
1 parent 729e535 commit 3e77e15
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 120 deletions.
107 changes: 61 additions & 46 deletions packages/rn-tester/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

static const NSTimeInterval kTestTimeoutSeconds = 120;

@implementation RCTTestRunner
{
@implementation RCTTestRunner {
FBSnapshotTestController *_testController;
RCTBridgeModuleListProvider _moduleProvider;
NSString *_appPath;
Expand Down Expand Up @@ -62,7 +61,8 @@ - (instancetype)initWithApp:(NSString *)app

if ((self = [super init])) {
if (!referenceDirectory.length) {
referenceDirectory = [[NSBundle bundleForClass:self.class].resourcePath stringByAppendingPathComponent:@"ReferenceImages"];
referenceDirectory =
[[NSBundle bundleForClass:self.class].resourcePath stringByAppendingPathComponent:@"ReferenceImages"];
}

NSString *sanitizedAppName = [app stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
Expand All @@ -82,13 +82,13 @@ - (instancetype)initWithApp:(NSString *)app
return self;
}

RCT_NOT_IMPLEMENTED(- (instancetype)init)
RCT_NOT_IMPLEMENTED(-(instancetype)init)

- (NSURL *)defaultScriptURL
{
if (getenv("CI_USE_PACKAGER") || _useBundler) {
NSString *bundlePrefix = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"RN_BUNDLE_PREFIX"];
return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@%@.bundle?platform=ios&dev=true", bundlePrefix, _appPath]];
return [NSURL
URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true", _appPath]];
} else {
return [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"];
}
Expand Down Expand Up @@ -121,53 +121,63 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
[self runTest:test module:moduleName initialProps:nil configurationBlock:nil expectErrorBlock:nil];
}

- (void)runTest:(SEL)test module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
- (void)runTest:(SEL)test
module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void (^)(RCTRootView *rootView))configurationBlock
{
[self runTest:test module:moduleName initialProps:initialProps configurationBlock:configurationBlock expectErrorBlock:nil];
[self runTest:test
module:moduleName
initialProps:initialProps
configurationBlock:configurationBlock
expectErrorBlock:nil];
}

- (void)runTest:(SEL)test module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
expectErrorRegex:(NSString *)errorRegex
- (void)runTest:(SEL)test
module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void (^)(RCTRootView *rootView))configurationBlock
expectErrorRegex:(NSString *)errorRegex
{
BOOL(^expectErrorBlock)(NSString *error) = ^BOOL(NSString *error){
BOOL (^expectErrorBlock)(NSString *error) = ^BOOL(NSString *error) {
return [error rangeOfString:errorRegex options:NSRegularExpressionSearch].location != NSNotFound;
};

[self runTest:test module:moduleName initialProps:initialProps configurationBlock:configurationBlock expectErrorBlock:expectErrorBlock];
[self runTest:test
module:moduleName
initialProps:initialProps
configurationBlock:configurationBlock
expectErrorBlock:expectErrorBlock];
}

- (void)runTest:(SEL)test module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock
expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock
- (void)runTest:(SEL)test
module:(NSString *)moduleName
initialProps:(NSDictionary<NSString *, id> *)initialProps
configurationBlock:(void (^)(RCTRootView *rootView))configurationBlock
expectErrorBlock:(BOOL (^)(NSString *error))expectErrorBlock
{
__weak RCTBridge *batchedBridge;
NSNumber *rootTag;
RCTLogFunction defaultLogFunction = RCTGetLogFunction();
// Catch all error logs, that are equivalent to redboxes in dev mode.
__block NSMutableArray<NSString *> *errors = nil;
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
defaultLogFunction(level, source, fileName, lineNumber, message);
if (level >= RCTLogLevelError) {
if (errors == nil) {
errors = [NSMutableArray new];
}
[errors addObject:message];
}
});
RCTSetLogFunction(
^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
defaultLogFunction(level, source, fileName, lineNumber, message);
if (level >= RCTLogLevelError) {
if (errors == nil) {
errors = [NSMutableArray new];
}
[errors addObject:message];
}
});

@autoreleasepool {
RCTBridge *bridge;
if (_bridgeDelegate) {
bridge = [[RCTBridge alloc] initWithDelegate:_bridgeDelegate launchOptions:nil];
} else {
bridge= [[RCTBridge alloc] initWithBundleURL:_scriptURL
moduleProvider:_moduleProvider
launchOptions:nil];
bridge = [[RCTBridge alloc] initWithBundleURL:_scriptURL moduleProvider:_moduleProvider launchOptions:nil];
}
[bridge.devSettings setIsDebuggingRemotely:_useJSDebugger];
batchedBridge = [bridge batchedBridge];
Expand All @@ -183,7 +193,9 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName

@autoreleasepool {
// The rootView needs to be deallocated after this @autoreleasepool block exits.
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProps];
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
#else
Expand All @@ -210,20 +222,22 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
}

// From this point on catch only fatal errors.
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
defaultLogFunction(level, source, fileName, lineNumber, message);
if (level >= RCTLogLevelFatal) {
if (errors == nil) {
errors = [NSMutableArray new];
}
[errors addObject:message];
}
});
RCTSetLogFunction(
^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
defaultLogFunction(level, source, fileName, lineNumber, message);
if (level >= RCTLogLevelFatal) {
if (errors == nil) {
errors = [NSMutableArray new];
}
[errors addObject:message];
}
});

#if RCT_DEV
NSArray<UIView *> *nonLayoutSubviews = [vc.view.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id subview, NSDictionary *bindings) {
return ![NSStringFromClass([subview class]) isEqualToString:@"_UILayoutGuide"];
}]];
NSArray<UIView *> *nonLayoutSubviews = [vc.view.subviews
filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id subview, NSDictionary *bindings) {
return ![NSStringFromClass([subview class]) isEqualToString:@"_UILayoutGuide"];
}]];

RCTAssert(nonLayoutSubviews.count == 0, @"There shouldn't be any other views: %@", nonLayoutSubviews);
#endif
Expand All @@ -232,7 +246,8 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
RCTAssert(expectErrorBlock(errors[0]), @"Expected an error but the first one was missing or did not match.");
} else {
RCTAssert(errors == nil, @"RedBox errors: %@", errors);
RCTAssert(testModule.status != RCTTestStatusPending, @"Test didn't finish within %0.f seconds", kTestTimeoutSeconds);
RCTAssert(
testModule.status != RCTTestStatusPending, @"Test didn't finish within %0.f seconds", kTestTimeoutSeconds);
RCTAssert(testModule.status == RCTTestStatusPassed, @"Test failed");
}

Expand Down
2 changes: 0 additions & 2 deletions packages/rn-tester/RNTester-tvOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@
</array>
<key>UIUserInterfaceStyle</key>
<string>Automatic</string>
<key>RN_BUNDLE_PREFIX</key>
<string>$(RN_BUNDLE_PREFIX)</string>
</dict>
</plist>
Loading

0 comments on commit 3e77e15

Please sign in to comment.