Fix for failing React tests

Since the JS test modules have been renamed to have consistent naming, we add a method to actually run the test methods to use our existing abstraction.
This commit is contained in:
Scott Kyle 2015-12-30 16:47:16 -08:00
parent b3a0627a51
commit 3739fab57f
2 changed files with 23 additions and 16 deletions

View File

@ -15,7 +15,9 @@ var SPECIAL_METHODS = {
afterEach: true, afterEach: true,
}; };
Object.defineProperty(exports, 'getTestNames', { // Only the test suites should be iterable members of exports.
Object.defineProperties(exports, {
getTestNames: {
value: function() { value: function() {
var testNames = {}; var testNames = {};
@ -29,4 +31,10 @@ Object.defineProperty(exports, 'getTestNames', {
return testNames; return testNames;
} }
},
runTest: {
value: function(suiteName, testName) {
exports[suiteName][testName]();
}
},
}); });

View File

@ -79,7 +79,7 @@ extern NSMutableArray *RCTGetModuleClasses(void);
} }
NSError *error; NSError *error;
NSDictionary *testCaseNames = [self invokeMethod:@"getTestNames" inModule:@"index" error:&error]; NSDictionary *testCaseNames = [self invokeMethod:@"getTestNames" arguments:nil error:&error];
if (error || !testCaseNames.count) { if (error || !testCaseNames.count) {
NSLog(@"Error from calling getTestNames() - %@", error ?: @"None returned"); NSLog(@"Error from calling getTestNames() - %@", error ?: @"None returned");
@ -128,14 +128,13 @@ extern NSMutableArray *RCTGetModuleClasses(void);
} }
} }
+ (id)invokeMethod:(NSString *)method inModule:(NSString *)module error:(NSError * __strong *)outError { + (id)invokeMethod:(NSString *)method arguments:(NSArray *)arguments error:(NSError * __strong *)outError {
id<RCTJavaScriptExecutor> executor = [self currentExecutor]; id<RCTJavaScriptExecutor> executor = [self currentExecutor];
module = [NSString stringWithFormat:@"realm-tests/%@.js", module];
__block BOOL condition = NO; __block BOOL condition = NO;
__block id result; __block id result;
[executor executeJSCall:module method:method arguments:@[] callback:^(id json, NSError *error) { [executor executeJSCall:@"realm-tests/index.js" method:method arguments:(arguments ?: @[]) callback:^(id json, NSError *error) {
// The React Native debuggerWorker.js very bizarrely returns an array five empty arrays to signify an error. // The React Native debuggerWorker.js very bizarrely returns an array five empty arrays to signify an error.
if ([json isKindOfClass:[NSArray class]] && [json isEqualToArray:@[@[], @[], @[], @[], @[]]]) { if ([json isKindOfClass:[NSArray class]] && [json isEqualToArray:@[@[], @[], @[], @[], @[]]]) {
json = nil; json = nil;
@ -169,7 +168,7 @@ extern NSMutableArray *RCTGetModuleClasses(void);
} }
NSError *error; NSError *error;
[self.class invokeMethod:method inModule:module error:&error]; [self.class invokeMethod:@"runTest" arguments:@[module, method] error:&error];
if (error) { if (error) {
// TODO: Parse and use localizedFailureReason info once we can source map the failure location in JS. // TODO: Parse and use localizedFailureReason info once we can source map the failure location in JS.