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:
parent
b3a0627a51
commit
3739fab57f
|
@ -15,18 +15,26 @@ var SPECIAL_METHODS = {
|
|||
afterEach: true,
|
||||
};
|
||||
|
||||
Object.defineProperty(exports, 'getTestNames', {
|
||||
value: function() {
|
||||
var testNames = {};
|
||||
// Only the test suites should be iterable members of exports.
|
||||
Object.defineProperties(exports, {
|
||||
getTestNames: {
|
||||
value: function() {
|
||||
var testNames = {};
|
||||
|
||||
for (var suiteName in exports) {
|
||||
var testSuite = exports[suiteName];
|
||||
for (var suiteName in exports) {
|
||||
var testSuite = exports[suiteName];
|
||||
|
||||
testNames[suiteName] = Object.keys(testSuite).filter(function(testName) {
|
||||
return !(testName in SPECIAL_METHODS) && typeof testSuite[testName] == 'function';
|
||||
});
|
||||
testNames[suiteName] = Object.keys(testSuite).filter(function(testName) {
|
||||
return !(testName in SPECIAL_METHODS) && typeof testSuite[testName] == 'function';
|
||||
});
|
||||
}
|
||||
|
||||
return testNames;
|
||||
}
|
||||
|
||||
return testNames;
|
||||
}
|
||||
},
|
||||
runTest: {
|
||||
value: function(suiteName, testName) {
|
||||
exports[suiteName][testName]();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -79,7 +79,7 @@ extern NSMutableArray *RCTGetModuleClasses(void);
|
|||
}
|
||||
|
||||
NSError *error;
|
||||
NSDictionary *testCaseNames = [self invokeMethod:@"getTestNames" inModule:@"index" error:&error];
|
||||
NSDictionary *testCaseNames = [self invokeMethod:@"getTestNames" arguments:nil error:&error];
|
||||
|
||||
if (error || !testCaseNames.count) {
|
||||
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];
|
||||
module = [NSString stringWithFormat:@"realm-tests/%@.js", module];
|
||||
|
||||
__block BOOL condition = NO;
|
||||
__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.
|
||||
if ([json isKindOfClass:[NSArray class]] && [json isEqualToArray:@[@[], @[], @[], @[], @[]]]) {
|
||||
json = nil;
|
||||
|
@ -169,7 +168,7 @@ extern NSMutableArray *RCTGetModuleClasses(void);
|
|||
}
|
||||
|
||||
NSError *error;
|
||||
[self.class invokeMethod:method inModule:module error:&error];
|
||||
[self.class invokeMethod:@"runTest" arguments:@[module, method] error:&error];
|
||||
|
||||
if (error) {
|
||||
// TODO: Parse and use localizedFailureReason info once we can source map the failure location in JS.
|
||||
|
|
Loading…
Reference in New Issue