Skip to content

Commit

Permalink
Report all errors from running tests
Browse files Browse the repository at this point in the history
Reviewed By: jingc

Differential Revision: D6526057

fbshipit-source-id: 00ebbb42aab17295350a24b92773c04593452608
  • Loading branch information
sahrens authored and facebook-github-bot committed Dec 9, 2017
1 parent 8f9b291 commit 3bcb912
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
__weak RCTBridge *batchedBridge;

@autoreleasepool {
__block NSString *error = nil;
__block NSMutableArray<NSString *> *errors = nil;
RCTLogFunction defaultLogFunction = RCTGetLogFunction();
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
defaultLogFunction(level, source, fileName, lineNumber, message);
if (level >= RCTLogLevelError) {
error = message;
if (errors == nil) {
errors = [NSMutableArray new];
}
[errors addObject:message];
}
});

Expand Down Expand Up @@ -155,7 +158,7 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
}

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:kTestTimeoutSeconds];
while (date.timeIntervalSinceNow > 0 && testModule.status == RCTTestStatusPending && error == nil) {
while (date.timeIntervalSinceNow > 0 && testModule.status == RCTTestStatusPending && errors == nil) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
Expand All @@ -173,9 +176,9 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
#endif

if (expectErrorBlock) {
RCTAssert(expectErrorBlock(error), @"Expected an error but nothing matched.");
RCTAssert(expectErrorBlock(errors[0]), @"Expected an error but the first one was missing or did not match.");
} else {
RCTAssert(error == nil, @"RedBox error: %@", error);
RCTAssert(errors == nil, @"RedBox errors: %@", errors);
RCTAssert(testModule.status != RCTTestStatusPending, @"Test didn't finish within %0.f seconds", kTestTimeoutSeconds);
RCTAssert(testModule.status == RCTTestStatusPassed, @"Test failed");
}
Expand Down

0 comments on commit 3bcb912

Please sign in to comment.