1// Copyright 2015-present 650 Industries. All rights reserved. 2 3#import "ExpoKit.h" 4#import "EXKernel.h" 5#import "EXKernelLinkingManager.h" 6#import "EXRootViewController.h" 7#import "EXShellManager.h" 8#import "EXTest.h" 9 10#import <React/RCTAssert.h> 11#import <React/RCTUtils.h> 12 13#import <XCTest/XCTest.h> 14 15@interface ExponentIntegrationTests : XCTestCase 16 17@property (nonatomic, strong) EXRootViewController *rootViewController; 18@property (nonatomic, strong) NSDictionary *jsTestSuiteResult; 19@property (nonatomic, strong) NSString *testSuiteUrl; 20 21@end 22 23@implementation ExponentIntegrationTests 24 25- (void)setUp 26{ 27 [super setUp]; 28 [self _loadConfig]; 29 30 _jsTestSuiteResult = nil; 31 _rootViewController = (EXRootViewController *)[ExpoKit sharedInstance].rootViewController; 32 [[NSNotificationCenter defaultCenter] addObserver:self 33 selector:@selector(_onKernelJSLoaded) 34 name:kEXKernelJSIsLoadedNotification 35 object:nil]; 36 [[NSNotificationCenter defaultCenter] addObserver:self 37 selector:@selector(_onTestSuiteCompleted:) 38 name:EXTestSuiteCompletedNotification object:nil]; 39} 40 41- (void)testDoesTestSuiteAppPassAllJSTests 42{ 43 XCTAssert((_testSuiteUrl), @"No url configured for JS test-suite. Make sure EXTestEnvironment.plist exists and contains a url to test-suite."); 44 [_rootViewController applicationWillEnterForeground]; 45 46 // wait for JS 47 NSDate *dateToTimeOut = [NSDate dateWithTimeIntervalSinceNow:60]; 48 while (dateToTimeOut.timeIntervalSinceNow > 0 && _jsTestSuiteResult == nil) { 49 [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 50 [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 51 } 52 XCTAssert((_jsTestSuiteResult), @"Test suite timed out"); 53 XCTAssert(([_jsTestSuiteResult[@"failed"] integerValue] == 0), @"Test suite failed: %@", _jsTestSuiteResult); 54} 55 56#pragma mark - internal 57 58- (void)_loadConfig 59{ 60 NSString *configPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"EXTestEnvironment" ofType:@"plist"]; 61 NSDictionary *testConfig = (configPath) ? [NSDictionary dictionaryWithContentsOfFile:configPath] : [NSDictionary dictionary]; 62 if (testConfig) { 63 _testSuiteUrl = testConfig[@"testSuiteUrl"]; 64 } 65} 66 67- (void)_onKernelJSLoaded 68{ 69 // if test environment isn't configured for a shell app, override here 70 // since clearly we're running tests 71 if ([EXShellManager sharedInstance].testEnvironment == EXTestEnvironmentNone) { 72 [EXShellManager sharedInstance].testEnvironment = EXTestEnvironmentLocal; 73 } 74 [[EXKernel sharedInstance].serviceRegistry.linkingManager openUrl:_testSuiteUrl isUniversalLink:NO]; 75} 76 77- (void)_onTestSuiteCompleted:(NSNotification *)notif 78{ 79 _jsTestSuiteResult = notif.userInfo; 80} 81 82@end 83