From 3bcb9127866ef60b3697553e98a3ae279d02290a Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Fri, 8 Dec 2017 16:38:27 -0800 Subject: [PATCH] Report all errors from running tests Reviewed By: jingc Differential Revision: D6526057 fbshipit-source-id: 00ebbb42aab17295350a24b92773c04593452608 --- Libraries/RCTTest/RCTTestRunner.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Libraries/RCTTest/RCTTestRunner.m b/Libraries/RCTTest/RCTTestRunner.m index 836d7bb77..2004e6a01 100644 --- a/Libraries/RCTTest/RCTTestRunner.m +++ b/Libraries/RCTTest/RCTTestRunner.m @@ -117,12 +117,15 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock __weak RCTBridge *batchedBridge; @autoreleasepool { - __block NSString *error = nil; + __block NSMutableArray *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]; } }); @@ -155,7 +158,7 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock } 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]]; } @@ -173,9 +176,9 @@ expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock #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"); }