diff --git a/CompanionLib/FBIDBCommandExecutor.h b/CompanionLib/FBIDBCommandExecutor.h index 3329acc6d..d0c19340a 100644 --- a/CompanionLib/FBIDBCommandExecutor.h +++ b/CompanionLib/FBIDBCommandExecutor.h @@ -291,6 +291,13 @@ This enables the permission popup the first time we open a deeplink */ - (FBFuture *> *)list_tests_in_bundle:(NSString *)bundleID with_app:(nullable NSString *)appPath; +/** + List the tests in an installed bundle using the file path of the bundle. + + @return a Future that resolves with names of tests in the bundle. + */ +- (FBFuture *> *)list_tests_in_bundle_file_path:(NSURL *)bundlePath; + /** Uninstall an application diff --git a/CompanionLib/FBIDBCommandExecutor.m b/CompanionLib/FBIDBCommandExecutor.m index a44bd6334..65d428300 100644 --- a/CompanionLib/FBIDBCommandExecutor.m +++ b/CompanionLib/FBIDBCommandExecutor.m @@ -319,6 +319,48 @@ - (instancetype)initWithTarget:(id)target storageManager:(FBIDBStor }]; } +- (FBFuture *> *)list_tests_in_bundle_file_path:(nonnull NSURL *)bundlePath { + NSError *error = nil; + id testDescriptor = nil; + + if ([bundlePath.pathExtension isEqualToString:@"xctest"]) { + FBBundleDescriptor *bundle = [FBBundleDescriptor bundleWithFallbackIdentifierFromPath:bundlePath.path error:&error]; + + if (!bundle) { + return [FBFuture futureWithError:error]; + } + + testDescriptor = [[FBXCTestBootstrapDescriptor alloc] initWithURL:bundlePath name:bundle.name testBundle:bundle]; + } + if ([bundlePath.pathExtension isEqualToString:@"xctestrun"]) { + NSArray> *descriptors = [self.storageManager.xctest getXCTestRunDescriptorsFromURL:bundlePath error:&error]; + + if (!descriptors) { + return [FBFuture futureWithError:error]; + } + if (descriptors.count != 1) { + return [[FBIDBError + describeFormat:@"Expected exactly one test in the xctestrun file, got: %lu", descriptors.count] + failFuture]; + } + + testDescriptor = descriptors[0]; + } + + if (!testDescriptor) { + return [FBFuture futureWithError:error]; + } + + id commands = (id) self.target; + if (![commands conformsToProtocol:@protocol(FBXCTestExtendedCommands)]) { + return [[FBIDBError + describeFormat:@"%@ does not conform to FBXCTestExtendedCommands", commands] + failFuture]; + } + + return [commands listTestsForBundleAtPath:testDescriptor.url.path timeout:ListTestBundleTimeout withAppAtPath:nil]; +} + - (FBFuture *)uninstall_application:(NSString *)bundleID { return [self.target uninstallApplicationWithBundleID:bundleID];