12a38a11eSExponent GitHub Bot// Copyright 2015-present 650 Industries. All rights reserved. 22a38a11eSExponent GitHub Bot 3d5e9e21bSBen Roth#import "ExpoKit.h" 4652b7dd7SBen Roth#import "EXKernel.h" 5652b7dd7SBen Roth#import "EXKernelLinkingManager.h" 6d5e9e21bSBen Roth#import "EXRootViewController.h" 766169681SBen Roth#import "EXHomeAppManager.h" 8652b7dd7SBen Roth#import "EXShellManager.h" 99aa11ec8SBen Roth#import "EXTest.h" 10d5e9e21bSBen Roth 11d5e9e21bSBen Roth#import <React/RCTAssert.h> 12d5e9e21bSBen Roth#import <React/RCTUtils.h> 132a38a11eSExponent GitHub Bot 142a38a11eSExponent GitHub Bot#import <XCTest/XCTest.h> 152a38a11eSExponent GitHub Bot 162a38a11eSExponent GitHub Bot@interface ExponentIntegrationTests : XCTestCase 172a38a11eSExponent GitHub Bot 18d5e9e21bSBen Roth@property (nonatomic, strong) EXRootViewController *rootViewController; 1967a01999SBen Roth@property (nonatomic, strong) NSString *testSuiteUrl; 20d5e9e21bSBen Roth 212a38a11eSExponent GitHub Bot@end 222a38a11eSExponent GitHub Bot 232a38a11eSExponent GitHub Bot@implementation ExponentIntegrationTests 242a38a11eSExponent GitHub Bot 252a38a11eSExponent GitHub Bot- (void)setUp 262a38a11eSExponent GitHub Bot{ 272a38a11eSExponent GitHub Bot [super setUp]; 2867a01999SBen Roth [self _loadConfig]; 299aa11ec8SBen Roth 30*5d8188f5SBen Roth _rootViewController = (EXRootViewController *)[ExpoKit sharedInstance].rootViewController; 31*5d8188f5SBen Roth // if test environment isn't configured for a shell app, override here 32*5d8188f5SBen Roth // since clearly we're running tests 33*5d8188f5SBen Roth if ([EXShellManager sharedInstance].testEnvironment == EXTestEnvironmentNone) { 34*5d8188f5SBen Roth [EXShellManager sharedInstance].testEnvironment = EXTestEnvironmentLocal; 35*5d8188f5SBen Roth } 36*5d8188f5SBen Roth 37*5d8188f5SBen Roth // NOTE(2018-02-20): Without giving the kernel a second to run, it never opens test-suite. With a 38*5d8188f5SBen Roth // cursory pass through the code, I didn't see the correct event to wait for. Perhaps after we 39*5d8188f5SBen Roth // implement a pure-native kernel, we'll be able to remove this shoddy delay. 40*5d8188f5SBen Roth dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 41*5d8188f5SBen Roth [[EXKernel sharedInstance].serviceRegistry.linkingManager openUrl:_testSuiteUrl isUniversalLink:NO]; 42*5d8188f5SBen Roth }); 43c6e145e8SJames Ide 442a38a11eSExponent GitHub Bot} 452a38a11eSExponent GitHub Bot 46d5e9e21bSBen Roth- (void)testDoesTestSuiteAppPassAllJSTests 472a38a11eSExponent GitHub Bot{ 4867a01999SBen Roth XCTAssert((_testSuiteUrl), @"No url configured for JS test-suite. Make sure EXTestEnvironment.plist exists and contains a url to test-suite."); 49c6e145e8SJames Ide 50c6e145e8SJames Ide XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription: @"Run all JS integration tests"]; 51c6e145e8SJames Ide 52c6e145e8SJames Ide __block NSDictionary *jsTestSuiteResult = nil; 53c6e145e8SJames Ide id<NSObject> observer = [NSNotificationCenter.defaultCenter 54c6e145e8SJames Ide addObserverForName:EXTestSuiteCompletedNotification 55c6e145e8SJames Ide object:nil 56c6e145e8SJames Ide queue:NSOperationQueue.currentQueue 57c6e145e8SJames Ide usingBlock:^(NSNotification *notification) { 58c6e145e8SJames Ide jsTestSuiteResult = notification.userInfo; 59c6e145e8SJames Ide [expectation fulfill]; 60c6e145e8SJames Ide }]; 612a38a11eSExponent GitHub Bot 62c6e145e8SJames Ide [self waitForExpectations:@[expectation] timeout:180]; 63c6e145e8SJames Ide [NSNotificationCenter.defaultCenter removeObserver:observer]; 64c6e145e8SJames Ide 65c6e145e8SJames Ide XCTAssert((jsTestSuiteResult), @"Test suite timed out"); 66c6e145e8SJames Ide XCTAssert(([jsTestSuiteResult[@"failed"] integerValue] == 0), @"Test suite failed: %@", jsTestSuiteResult); 679aa11ec8SBen Roth} 689aa11ec8SBen Roth 699aa11ec8SBen Roth#pragma mark - internal 709aa11ec8SBen Roth 7167a01999SBen Roth- (void)_loadConfig 7267a01999SBen Roth{ 7395925a0aSJames Ide // This plist is generated with `powertools configure-ios-test-suite-url` 7467a01999SBen Roth NSString *configPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"EXTestEnvironment" ofType:@"plist"]; 7567a01999SBen Roth NSDictionary *testConfig = (configPath) ? [NSDictionary dictionaryWithContentsOfFile:configPath] : [NSDictionary dictionary]; 7667a01999SBen Roth if (testConfig) { 7767a01999SBen Roth _testSuiteUrl = testConfig[@"testSuiteUrl"]; 7867a01999SBen Roth } 7967a01999SBen Roth} 8067a01999SBen Roth 812a38a11eSExponent GitHub Bot@end 82