Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9cf94bd

Browse files
committed
Merge pull request #10 from Microsoft/fix-update-issues
Fix update issues
2 parents c6dd347 + 3d25bdb commit 9cf94bd

17 files changed

+117
-94
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ DerivedData
9090
!default.perspectivev3
9191
xcuserdata
9292

93+
## OSX
94+
.DS_Store
95+
9396
## Other
9497
*.xccheckout
9598
*.moved-aside

CodePush.ios.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ var Sdk = require("code-push/script/acquisition-sdk").AcquisitionManager;
1212
var packageMixins = require("./package-mixins")(NativeCodePush);
1313

1414
// This function is only used for tests. Replaces the default SDK, configuration and native bridge
15-
function setUpTestDependencies(testSdk, testConfiguration, testNativeBridge){
16-
if (testSdk) sdk = testSdk;
17-
if (testConfiguration) config = testConfiguration;
15+
function setUpTestDependencies(providedTestSdk, providedTestConfig, testNativeBridge){
16+
if (providedTestSdk) testSdk = providedTestSdk;
17+
if (providedTestConfig) testConfig = providedTestConfig;
1818
if (testNativeBridge) NativeCodePush = testNativeBridge;
1919
}
20+
var testConfig;
21+
var testSdk;
2022

2123
var getConfiguration = (() => {
2224
var config;
2325
return function getConfiguration() {
2426
if (config) {
2527
return Promise.resolve(config);
28+
} else if (testConfig) {
29+
return Promise.resolve(testConfig);
2630
} else {
2731
return NativeCodePush.getConfiguration()
2832
.then((configuration) => {
@@ -38,6 +42,8 @@ var getSdk = (() => {
3842
return function getSdk() {
3943
if (sdk) {
4044
return Promise.resolve(sdk);
45+
} else if (testSdk) {
46+
return Promise.resolve(testSdk);
4147
} else {
4248
return getConfiguration()
4349
.then((configuration) => {

Examples/CodePushDemoApp/CodePushDemoApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
5451ACBA1B86A5B600E2A7DF /* QueryUpdateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5451ACB81B86A5B600E2A7DF /* QueryUpdateTests.m */; };
2626
5451ACEC1B86E40A00E2A7DF /* libRCTTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5451ACEB1B86E34300E2A7DF /* libRCTTest.a */; };
2727
54D774BA1B87DAF800F2ABF8 /* ApplyUpdateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D774B91B87DAF800F2ABF8 /* ApplyUpdateTests.m */; };
28-
810D4E6F1BA0E99300B397E9 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 810D4E6E1BA0E99300B397E9 /* main.jsbundle */; };
2928
81551E1B1B3B428000F5B9F1 /* libCodePush.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 81551E0F1B3B427200F5B9F1 /* libCodePush.a */; };
3029
/* End PBXBuildFile section */
3130

@@ -153,7 +152,6 @@
153152
5451ACE61B86E34300E2A7DF /* RCTTest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTTest.xcodeproj; path = "node_modules/react-native/Libraries/RCTTest/RCTTest.xcodeproj"; sourceTree = "<group>"; };
154153
54D774B91B87DAF800F2ABF8 /* ApplyUpdateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplyUpdateTests.m; sourceTree = "<group>"; };
155154
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
156-
810D4E6E1BA0E99300B397E9 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = main.jsbundle; path = iOS/main.jsbundle; sourceTree = "<group>"; };
157155
81551E0A1B3B427200F5B9F1 /* CodePush.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CodePush.xcodeproj; path = ../../CodePush.xcodeproj; sourceTree = "<group>"; };
158156
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
159157
/* End PBXFileReference section */
@@ -274,7 +272,6 @@
274272
13B07FAE1A68108700A75B9A /* CodePushDemoApp */ = {
275273
isa = PBXGroup;
276274
children = (
277-
810D4E6E1BA0E99300B397E9 /* main.jsbundle */,
278275
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
279276
13B07FB01A68108700A75B9A /* AppDelegate.m */,
280277
13B07FB51A68108700A75B9A /* Images.xcassets */,
@@ -598,7 +595,6 @@
598595
isa = PBXResourcesBuildPhase;
599596
buildActionMask = 2147483647;
600597
files = (
601-
810D4E6F1BA0E99300B397E9 /* main.jsbundle in Resources */,
602598
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
603599
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
604600
);

Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import "RCTRootView.h"
99
#import "RCTRedBox.h"
1010
#import "RCTAssert.h"
11+
#import "RCTLog.h"
1112

1213
#define FB_REFERENCE_IMAGE_DIR "\"$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages\""
1314

@@ -26,7 +27,7 @@ @implementation ApplyUpdateTests
2627

2728
- (void)setUp
2829
{
29-
app = @"CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp";
30+
app = @"CodePushDemoAppTests/ApplyUpdateTests/ApplyUpdateTestApp.ios";
3031
#if __LP64__
3132
RCTAssert(false, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
3233
#endif
@@ -66,16 +67,24 @@ - (void)testDownloadAndApplyUpdate
6667
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:scriptURL
6768
moduleProvider:nil
6869
launchOptions:nil];
69-
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"DownloadAndApplyUpdateTest"];
70-
70+
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
71+
moduleName:@"DownloadAndApplyUpdateTest"
72+
initialProperties:nil];
73+
7174
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
7275
BOOL foundElement = NO;
73-
NSString *redboxError = nil;
76+
77+
__block NSString *redboxError = nil;
78+
RCTSetLogFunction(^(RCTLogLevel level, NSString *fileName, NSNumber *lineNumber, NSString *message) {
79+
if (level >= RCTLogLevelError) {
80+
redboxError = message;
81+
}
82+
});
7483

7584
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
7685
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
7786
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
78-
redboxError = [[RCTRedBox sharedInstance] currentErrorMessage];
87+
7988
UIViewController *vc = [UIApplication sharedApplication].delegate.window.rootViewController;
8089
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
8190
if ([NSStringFromClass([view class]) isEqualToString:@"RCTText"]){

Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ var NativeCodePush = require('react-native').NativeModules.CodePush;
1919
var CodePushDemoApp = React.createClass({
2020
componentDidMount: function() {
2121
NativeCodePush.setUsingTestFolder(true);
22-
NativeCodePush.getLocalPackage(function(err, savedPackage) {
23-
if (err || !savedPackage) {
24-
throw new Error("The updated package was not saved");
25-
} else {
26-
var testPackage = require("./TestPackage");
27-
for (var key in testPackage) {
28-
if (savedPackage[key] !== testPackage[key]) {
29-
throw new Error("The local package is still different from the updated package after installation");
22+
NativeCodePush.getCurrentPackage().then(
23+
(savedPackage) => {
24+
if (savedPackage) {
25+
var testPackage = require("./TestPackage");
26+
for (var key in testPackage) {
27+
if (savedPackage[key] !== testPackage[key]) {
28+
throw new Error("The local package is still different from the updated package after installation");
29+
}
3030
}
31+
} else {
32+
throw new Error("The updated package was not saved");
3133
}
34+
},
35+
(err) => {
36+
throw new Error("The updated package was not saved");
3237
}
33-
});
38+
);
3439
},
3540
render: function() {
3641
return (

Examples/CodePushDemoApp/CodePushDemoAppTests/ApplyUpdateTests/DownloadAndApplyUpdateTest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ var DownloadAndApplyUpdateTest = React.createClass({
3838

3939
runTest() {
4040
var update = require("./TestPackage");
41-
CodePushSdk.installUpdate(update);
41+
NativeBridge.downloadUpdate(update).done((downloadedPackage) => {
42+
NativeBridge.applyUpdate(downloadedPackage, 1000);
43+
});
4244
},
4345

4446
render() {

Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ - (void)setUp
2323

2424
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
2525
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);
26-
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/QueryUpdateTests/QueryUpdateTestApp", nil);
26+
_runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/QueryUpdateTests/QueryUpdateTestApp.ios", nil);
2727
}
2828

2929
#pragma mark Logic Tests

Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests/FirstUpdateTest.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ var FirstUpdateTest = React.createClass({
5757
NativeBridge.setUsingTestFolder(true);
5858
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
5959

60-
NativeBridge.removeLocalPackage(function(err){
61-
if (err) {
62-
throw new Error('Setup: Error removing local package');
63-
} else {
64-
callWhenDone();
65-
}
66-
});
60+
CodePushSdk.getCurrentPackage = function () {
61+
return Promise.resolve(null);
62+
}
63+
callWhenDone();
6764
},
6865

6966
runTest() {
70-
CodePushSdk.queryUpdate((err, update) => {
71-
if (update) {
72-
this.setState({done: true}, RCTTestModule.markTestCompleted);
73-
} else if (err) {
67+
CodePushSdk.checkForUpdate().then(
68+
(update) => {
69+
if (update) {
70+
throw new Error('SDK should return a package when there is an update');
71+
} else {
72+
this.setState({done: true}, RCTTestModule.markTestCompleted);
73+
}
74+
},
75+
(err) => {
7476
throw new Error(err.message);
75-
} else {
76-
throw new Error('SDK should return a package when there is an update');
77-
}
78-
});
77+
},
78+
);
7979
},
8080

8181
render() {

Examples/CodePushDemoApp/CodePushDemoAppTests/QueryUpdateTests/NewUpdateTest.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ var NewUpdateTest = React.createClass({
6969
NativeBridge.setUsingTestFolder(true);
7070
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
7171

72-
NativeBridge.writeToLocalPackage(localPackage, function(err){
73-
if (err) {
74-
throw new Error('Setup: Error removing local package');
75-
} else {
76-
callWhenDone();
77-
}
78-
});
72+
CodePushSdk.getCurrentPackage = function () {
73+
return Promise.resolve(localPackage);
74+
}
75+
callWhenDone();
7976
},
8077

8178
runTest() {
82-
CodePushSdk.queryUpdate((err, update) => {
83-
if (update) {
84-
this.setState({done: true}, RCTTestModule.markTestCompleted);
85-
} else if (err) {
79+
CodePushSdk.checkForUpdate().then(
80+
(update) => {
81+
if (update) {
82+
throw new Error('SDK should return a package when there is a new update');
83+
} else {
84+
this.setState({done: true}, RCTTestModule.markTestCompleted);
85+
}
86+
},
87+
(err) => {
8688
throw new Error(err.message);
87-
} else {
88-
throw new Error('SDK should return a package when there is a new update');
89-
}
90-
});
89+
},
90+
);
9191
},
9292

9393
render() {

0 commit comments

Comments
 (0)