From 3739fab57f9999970534571d7921e72e47d126ba Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Wed, 30 Dec 2015 16:47:16 -0800 Subject: [PATCH] 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. --- tests/lib/index.js | 30 ++++++++++++------- .../ios/ReactTests/RealmReactTests.m | 9 +++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/lib/index.js b/tests/lib/index.js index 0518ca14..3ef1db86 100644 --- a/tests/lib/index.js +++ b/tests/lib/index.js @@ -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](); + } + }, }); diff --git a/tests/react-test-app/ios/ReactTests/RealmReactTests.m b/tests/react-test-app/ios/ReactTests/RealmReactTests.m index b071adfa..df321edd 100644 --- a/tests/react-test-app/ios/ReactTests/RealmReactTests.m +++ b/tests/react-test-app/ios/ReactTests/RealmReactTests.m @@ -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 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.