From cb5e8a267742d460845bb55a8116ee7cde7f2a6c Mon Sep 17 00:00:00 2001 From: kg422 Date: Mon, 24 Aug 2015 18:21:26 -0700 Subject: [PATCH] readme modifications, removed copyrights, fixed issue with install update test --- .../CodePushDemoApp.xcodeproj/project.pbxproj | 12 +-- .../CodePushDemoAppTests/ApplyUpdateTests.m | 78 ++++++++++++++++--- .../ApplyUpdateTests/ApplyUpdateTestApp.js | 7 -- .../ApplyUpdateTests/CodePushDemoApp.ios.js | 1 - .../DownloadAndApplyUpdateTest.js | 9 --- .../CodePushDemoAppTests/QueryUpdateTests.m | 12 +-- Examples/CodePushDemoApp/iOS/Info.plist | 4 +- README.md | 11 ++- 8 files changed, 86 insertions(+), 48 deletions(-) diff --git a/Examples/CodePushDemoApp/CodePushDemoApp.xcodeproj/project.pbxproj b/Examples/CodePushDemoApp/CodePushDemoApp.xcodeproj/project.pbxproj index 187f1b1..a8fd9c7 100644 --- a/Examples/CodePushDemoApp/CodePushDemoApp.xcodeproj/project.pbxproj +++ b/Examples/CodePushDemoApp/CodePushDemoApp.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; }; 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E61ABCBA2D00DB3ED1 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302B41ABCB8E700DB3ED1 /* libRCTAdSupport.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -22,11 +21,12 @@ 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; }; + 544161591B8BCA81000D9E25 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; + 5441615B1B8BF2BB000D9E25 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 5441615A1B8BF2BB000D9E25 /* main.jsbundle */; }; 5451ACBA1B86A5B600E2A7DF /* QueryUpdateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5451ACB81B86A5B600E2A7DF /* QueryUpdateTests.m */; }; 5451ACEC1B86E40A00E2A7DF /* libRCTTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5451ACEB1B86E34300E2A7DF /* libRCTTest.a */; }; 54D774BA1B87DAF800F2ABF8 /* ApplyUpdateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D774B91B87DAF800F2ABF8 /* ApplyUpdateTests.m */; }; 81551E1B1B3B428000F5B9F1 /* libCodePush.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 81551E0F1B3B427200F5B9F1 /* libCodePush.a */; }; - 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -131,7 +131,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = ""; }; 00C302A71ABCB8CE00DB3ED1 /* RCTActionSheet.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTActionSheet.xcodeproj; path = "node_modules/react-native/Libraries/ActionSheetIOS/RCTActionSheet.xcodeproj"; sourceTree = ""; }; 00C302AF1ABCB8E700DB3ED1 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = "node_modules/react-native/Libraries/AdSupport/RCTAdSupport.xcodeproj"; sourceTree = ""; }; 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = "node_modules/react-native/Libraries/Geolocation/RCTGeolocation.xcodeproj"; sourceTree = ""; }; @@ -150,6 +149,7 @@ 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = iOS/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = iOS/main.m; sourceTree = ""; }; 146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "node_modules/react-native/React/React.xcodeproj"; sourceTree = ""; }; + 5441615A1B8BF2BB000D9E25 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = ""; }; 5451ACB81B86A5B600E2A7DF /* QueryUpdateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QueryUpdateTests.m; sourceTree = ""; }; 5451ACE61B86E34300E2A7DF /* RCTTest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTTest.xcodeproj; path = "node_modules/react-native/Libraries/RCTTest/RCTTest.xcodeproj"; sourceTree = ""; }; 54D774B91B87DAF800F2ABF8 /* ApplyUpdateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplyUpdateTests.m; sourceTree = ""; }; @@ -170,6 +170,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 544161591B8BCA81000D9E25 /* libRCTText.a in Frameworks */, 5451ACEC1B86E40A00E2A7DF /* libRCTTest.a in Frameworks */, 146834051AC3E58100842450 /* libReact.a in Frameworks */, 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */, @@ -179,7 +180,6 @@ 133E29F31AD74F7200F7D852 /* libRCTLinking.a in Frameworks */, 00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */, 139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */, - 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */, 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, 81551E1B1B3B428000F5B9F1 /* libCodePush.a in Frameworks */, @@ -274,7 +274,7 @@ 13B07FAE1A68108700A75B9A /* CodePushDemoApp */ = { isa = PBXGroup; children = ( - 008F07F21AC5B25A0029DE68 /* main.jsbundle */, + 5441615A1B8BF2BB000D9E25 /* main.jsbundle */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.m */, 13B07FB51A68108700A75B9A /* Images.xcassets */, @@ -598,7 +598,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */, + 5441615B1B8BF2BB000D9E25 /* main.jsbundle in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, ); diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests.m b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests.m index 8d6916c..879bd96 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests.m +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests.m @@ -1,19 +1,19 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - - #import #import #import +#import "RCTBridge.h" +#import "RCTBridgeModule.h" +#import "RCTDefines.h" +#import "RCTRootView.h" +#import "RCTRedBox.h" #import "RCTAssert.h" +#define FB_REFERENCE_IMAGE_DIR "\"$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages\"" + +#define TIMEOUT_SECONDS 60 +#define TEXT_TO_LOOK_FOR @"If you see this, you have successfully installed an update!" + @interface ApplyUpdateTests : XCTestCase @end @@ -21,24 +21,78 @@ @implementation ApplyUpdateTests { RCTTestRunner *_runner; + NSString* app; } - (void)setUp { + app = @"CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp"; #if __LP64__ RCTAssert(false, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)"); #endif NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; RCTAssert(version.majorVersion == 8 || version.minorVersion == 3, @"Tests should be run on iOS 8.3, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion); - _runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp", nil); +} + + +- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test +{ + if (test(view)) { + return YES; + } + for (UIView *subview in [view subviews]) { + if ([self findSubviewInView:subview matching:test]) { + return YES; + } + } + return NO; } #pragma mark Logic Tests - (void)testDownloadAndApplyUpdate { - [_runner runTest:_cmd module:@"DownloadAndApplyUpdateTest"]; + + NSString *sanitizedAppName = [app stringByReplacingOccurrencesOfString:@"/" withString:@"-"]; + sanitizedAppName = [sanitizedAppName stringByReplacingOccurrencesOfString:@"\\" withString:@"-"]; + NSURL* scriptURL; + +#if RUNNING_ON_CI + scriptURL = [[NSBundle bundleForClass:[RCTBridge class]] URLForResource:@"main" withExtension:@"jsbundle"]; + RCTAssert(_scriptURL != nil, @"Could not locate main.jsBundle"); +#else + scriptURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.includeRequire.runModule.bundle?dev=true", app]]; +#endif + + RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:scriptURL + moduleProvider:nil + launchOptions:nil]; + RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"DownloadAndApplyUpdateTest"]; + + NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; + BOOL foundElement = NO; + NSString *redboxError = nil; + + while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { + [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; + [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; + redboxError = [[RCTRedBox sharedInstance] currentErrorMessage]; + UIViewController *vc = [UIApplication sharedApplication].delegate.window.rootViewController; + foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { + if ([NSStringFromClass([view class]) isEqualToString:@"RCTText"]){ + NSString *text = [(id)view textStorage].string; + if ([text isEqualToString:TEXT_TO_LOOK_FOR]) { + return YES; + } + } + + return NO; + }]; + } + + XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); + XCTAssertTrue(foundElement, @"Cound't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); } diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp.js index 85d62a9..37cbb33 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp.js @@ -1,11 +1,4 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * * @providesModule QueryUpdateTestApp */ 'use strict'; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.js index ef22d2d..dd8fef1 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.js @@ -29,7 +29,6 @@ var CodePushDemoApp = React.createClass({ throw new Error("The local package is still different from the updated package after installation"); } } - RCTTestModule.markTestCompleted(); } }); }, diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/DownloadAndApplyUpdateTest.js b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/DownloadAndApplyUpdateTest.js index c96b970..5b6b510 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/DownloadAndApplyUpdateTest.js +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/DownloadAndApplyUpdateTest.js @@ -1,14 +1,5 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ 'use strict'; -var RCTTestModule = require('NativeModules').TestModule; var React = require('react-native'); var CodePushSdk = require('react-native-code-push'); var NativeBridge = require('react-native').NativeModules.CodePush; diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests.m b/Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests.m index 93aecaf..1e99ea0 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests.m +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests.m @@ -1,19 +1,11 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - - #import #import #import #import "RCTAssert.h" +#define FB_REFERENCE_IMAGE_DIR "\"$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages\"" + @interface QueryUpdateTests : XCTestCase @end diff --git a/Examples/CodePushDemoApp/iOS/Info.plist b/Examples/CodePushDemoApp/iOS/Info.plist index 20d5f27..43758af 100644 --- a/Examples/CodePushDemoApp/iOS/Info.plist +++ b/Examples/CodePushDemoApp/iOS/Info.plist @@ -39,8 +39,8 @@ NSLocationWhenInUseUsageDescription CodePushDeploymentKey - deployment-key-here + 3fd3773b-4554-4f56-b7d7-ce5b587f54de CodePushServerUrl - server-url-here + http://localhost:3000 diff --git a/README.md b/README.md index 73f474f..2ffbfdd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,16 @@ Running the Example * Start the CodePush server with `gulp serve`, after installing the prerequisites described in the [project readme](https://github.com/Microsoft/hybrid-mobile-deploy/blob/master/README.md) * From the root of this project, run `npm install` * `cd` into `Examples/CodePushDemoApp` -* Open `index.ios.js` and add a deployment key (generate one using the UI at http://localhost:4000/) +* From this demo app folder, run `npm install` +* Open `Info.plist` and fill in the values for CodePushDeploymentKey and CodePushServerUrl * Run `npm start` to launch the packager * Open `CodePushDemoApp.xcodeproj` in Xcode * Launch the project + +Running Tests +--- + +* Open `CodePushDemoApp.xcodeproj` in Xcode +* Navigate to the test explorer (small grey diamond near top left) +* Click on the 'play' button next to CodePushDemoAppTests +* After the tests are completed, green ticks should appear next to the test cases to indicate success \ No newline at end of file