Skip to content

Commit

Permalink
Fixes template build failed in release mode (#25751)
Browse files Browse the repository at this point in the history
Summary:
Fixes #25745, Xcode stripped dead code in Release mode, and in template test code, it should only run in Debug mode, so we can use a macro to fix this issue.

## Changelog

[iOS] [Fixed] - Fixes template build failed in release mode
Pull Request resolved: #25751

Test Plan:
1. Create a new project using `react-native init AwesomProject`.
2. Change project target scheme to `Release`.
3. Build and it should success.

Differential Revision: D16442643

Pulled By: TheSavior

fbshipit-source-id: f08ed70523aa1aa418064465f8df367a06e8974f
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Jul 23, 2019
1 parent cf77067 commit 0fcaca8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion template/ios/HelloWorldTests/HelloWorldTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ - (void)testRendersWelcomeScreen
BOOL foundElement = NO;

__block NSString *redboxError = nil;
#ifdef DEBUG
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});
#endif

while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
Expand All @@ -57,8 +59,10 @@ - (void)testRendersWelcomeScreen
return NO;
}];
}


#ifdef DEBUG
RCTSetLogFunction(RCTDefaultLogFunction);
#endif

XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
Expand Down

0 comments on commit 0fcaca8

Please sign in to comment.