Skip to content

Commit 3bcb912

Browse files
sahrensfacebook-github-bot
authored andcommitted
Report all errors from running tests
Reviewed By: jingc Differential Revision: D6526057 fbshipit-source-id: 00ebbb42aab17295350a24b92773c04593452608
1 parent 8f9b291 commit 3bcb912

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Libraries/RCTTest/RCTTestRunner.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,15 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
117117
__weak RCTBridge *batchedBridge;
118118

119119
@autoreleasepool {
120-
__block NSString *error = nil;
120+
__block NSMutableArray<NSString *> *errors = nil;
121121
RCTLogFunction defaultLogFunction = RCTGetLogFunction();
122122
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
123123
defaultLogFunction(level, source, fileName, lineNumber, message);
124124
if (level >= RCTLogLevelError) {
125-
error = message;
125+
if (errors == nil) {
126+
errors = [NSMutableArray new];
127+
}
128+
[errors addObject:message];
126129
}
127130
});
128131

@@ -155,7 +158,7 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName
155158
}
156159

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

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

0 commit comments

Comments
 (0)