mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-11 08:04:23 +08:00
wrote QueryUpdate and ApplyUpdate tests
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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 <UIKit/UIKit.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import <RCTTest/RCTTestRunner.h>
|
||||
|
||||
#import "RCTAssert.h"
|
||||
|
||||
@interface ApplyUpdateTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation ApplyUpdateTests
|
||||
{
|
||||
RCTTestRunner *_runner;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
#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);
|
||||
}
|
||||
|
||||
#pragma mark Logic Tests
|
||||
- (void)testDownloadAndApplyUpdate
|
||||
{
|
||||
|
||||
[_runner runTest:_cmd module:@"DownloadAndApplyUpdateTest"];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
var React = require('react-native');
|
||||
|
||||
var {
|
||||
AppRegistry,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var TESTS = [
|
||||
require('./DownloadAndApplyUpdateTest')
|
||||
];
|
||||
|
||||
TESTS.forEach(
|
||||
(test) => AppRegistry.registerComponent(test.displayName, () => test)
|
||||
);
|
||||
|
||||
var ApplyUpdateTestApp = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
test: null,
|
||||
};
|
||||
},
|
||||
render: function() {
|
||||
if (this.state.test) {
|
||||
return (
|
||||
<ScrollView>
|
||||
<this.state.test />
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.row}>
|
||||
Click on a test to run it in this shell for easier debugging and
|
||||
development. Run all tests in the testing environment with cmd+U in
|
||||
Xcode.
|
||||
</Text>
|
||||
<View style={styles.separator} />
|
||||
<ScrollView>
|
||||
{TESTS.map((test) => [
|
||||
<TouchableOpacity
|
||||
onPress={() => this.setState({test})}
|
||||
style={styles.row}>
|
||||
<Text style={styles.testName}>
|
||||
{test.displayName}
|
||||
</Text>
|
||||
</TouchableOpacity>,
|
||||
<View style={styles.separator} />
|
||||
])}
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
backgroundColor: 'white',
|
||||
marginTop: 40,
|
||||
margin: 15,
|
||||
},
|
||||
row: {
|
||||
padding: 10,
|
||||
},
|
||||
testName: {
|
||||
fontWeight: '500',
|
||||
},
|
||||
separator: {
|
||||
height: 1,
|
||||
backgroundColor: '#bbbbbb',
|
||||
}
|
||||
});
|
||||
|
||||
AppRegistry.registerComponent('ApplyUpdateTestApp', () => ApplyUpdateTestApp);
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Sample React Native App
|
||||
* https://github.com/facebook/react-native
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var React = require('react-native');
|
||||
var {
|
||||
AppRegistry,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var RCTTestModule = require('NativeModules').TestModule;
|
||||
var NativeCodePush = require('react-native').NativeModules.CodePush;
|
||||
|
||||
var CodePushDemoApp = React.createClass({
|
||||
componentDidMount: function() {
|
||||
NativeCodePush.setUsingTestFolder(true);
|
||||
NativeCodePush.getLocalPackage(function(err, savedPackage) {
|
||||
if (err || !savedPackage) {
|
||||
throw new Error("The updated package was not saved");
|
||||
} else {
|
||||
var testPackage = require("./TestPackage");
|
||||
for (var key in testPackage) {
|
||||
if (savedPackage[key] !== testPackage[key]) {
|
||||
throw new Error("The local package is still different from the updated package after installation");
|
||||
}
|
||||
}
|
||||
RCTTestModule.markTestCompleted();
|
||||
}
|
||||
});
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>
|
||||
If you see this, you have successfully installed an update!
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
backgroundColor: '#F5FCFF',
|
||||
},
|
||||
welcome: {
|
||||
fontSize: 20,
|
||||
textAlign: 'center',
|
||||
margin: 10,
|
||||
}
|
||||
});
|
||||
|
||||
AppRegistry.registerComponent('CodePushDemoApp', () => CodePushDemoApp);
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var DownloadAndApplyUpdateTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp();
|
||||
this.runTest();
|
||||
}
|
||||
},
|
||||
|
||||
setUp(callWhenDone) {
|
||||
var mockConfiguration = { appVersion : "1.5.0" };
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
CodePushSdk.setUpTestDependencies(null, mockConfiguration, NativeBridge);
|
||||
},
|
||||
|
||||
runTest() {
|
||||
var update = require("./TestPackage");
|
||||
CodePushSdk.installUpdate(update);
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
DownloadAndApplyUpdateTest.displayName = 'DownloadAndApplyUpdateTest';
|
||||
|
||||
module.exports = DownloadAndApplyUpdateTest;
|
||||
@@ -0,0 +1,13 @@
|
||||
var testPackage = {
|
||||
downloadUrl: "http://localhost:8081/CodePushDemoAppTests/ApplyUpdateTests/CodePushDemoApp.ios.includeRequire.runModule.bundle?dev=true",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
};
|
||||
|
||||
module.exports = testPackage;
|
||||
24
Examples/CodePushDemoApp/CodePushDemoAppTests/Info.plist
Normal file
24
Examples/CodePushDemoApp/CodePushDemoAppTests/Info.plist
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 <UIKit/UIKit.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import <RCTTest/RCTTestRunner.h>
|
||||
|
||||
#import "RCTAssert.h"
|
||||
|
||||
@interface QueryUpdateTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation QueryUpdateTests
|
||||
{
|
||||
RCTTestRunner *_runner;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
#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/QueryUpdateTests/QueryUpdateTestApp", nil);
|
||||
}
|
||||
|
||||
#pragma mark Logic Tests
|
||||
- (void)testNoRemotePackage
|
||||
{
|
||||
|
||||
[_runner runTest:_cmd module:@"NoRemotePackageTest"];
|
||||
}
|
||||
|
||||
- (void)testNoRemotePackageWithSameAppVersion
|
||||
{
|
||||
[_runner runTest:_cmd
|
||||
module:@"NoRemotePackageWithSameAppVersionTest"];
|
||||
}
|
||||
|
||||
- (void)testFirstUpdate
|
||||
{
|
||||
[_runner runTest:_cmd
|
||||
module:@"FirstUpdateTest"];
|
||||
}
|
||||
|
||||
- (void)testNewUpdate
|
||||
{
|
||||
[_runner runTest:_cmd
|
||||
module:@"NewUpdateTest"];
|
||||
}
|
||||
|
||||
- (void)testSamePackage
|
||||
{
|
||||
[_runner runTest:_cmd
|
||||
module:@"SamePackageTest"];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var FirstUpdateTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp(this.runTest);
|
||||
}
|
||||
},
|
||||
|
||||
setUp(callWhenDone) {
|
||||
var mockAcquisitionSdk = {
|
||||
latestPackage: {
|
||||
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
},
|
||||
queryUpdateWithCurrentPackage: function(queryPackage, callback){
|
||||
if (!this.latestPackage || queryPackage.appVersion !== this.latestPackage.appVersion ||
|
||||
queryPackage.packageHash == this.latestPackage.packageHash) {
|
||||
callback(/*err:*/ null, false);
|
||||
} else {
|
||||
callback(/*err:*/ null, this.latestPackage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var mockConfiguration = { appVersion : "1.5.0" };
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
|
||||
|
||||
NativeBridge.removeLocalPackage(function(err){
|
||||
if (err) {
|
||||
throw new Error('Setup: Error removing local package');
|
||||
} else {
|
||||
callWhenDone();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runTest() {
|
||||
CodePushSdk.queryUpdate((err, update) => {
|
||||
if (update) {
|
||||
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
||||
} else if (err) {
|
||||
throw new Error(err.message);
|
||||
} else {
|
||||
throw new Error('SDK should return a package when there is an update');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
FirstUpdateTest.displayName = 'FirstUpdateTest';
|
||||
|
||||
module.exports = FirstUpdateTest;
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var NewUpdateTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp(this.runTest);
|
||||
}
|
||||
},
|
||||
|
||||
setUp(callWhenDone) {
|
||||
var mockAcquisitionSdk = {
|
||||
latestPackage: {
|
||||
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
},
|
||||
queryUpdateWithCurrentPackage: function(queryPackage, callback){
|
||||
if (!this.latestPackage || queryPackage.appVersion !== this.latestPackage.appVersion ||
|
||||
queryPackage.packageHash == this.latestPackage.packageHash) {
|
||||
callback(/*err:*/ null, false);
|
||||
} else {
|
||||
callback(/*err:*/ null, this.latestPackage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var localPackage = JSON.stringify({
|
||||
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash123",
|
||||
packageSize: 1024
|
||||
});
|
||||
|
||||
var mockConfiguration = { appVersion : "1.5.0" };
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
|
||||
|
||||
NativeBridge.writeToLocalPackage(localPackage, function(err){
|
||||
if (err) {
|
||||
throw new Error('Setup: Error removing local package');
|
||||
} else {
|
||||
callWhenDone();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runTest() {
|
||||
CodePushSdk.queryUpdate((err, update) => {
|
||||
if (update) {
|
||||
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
||||
} else if (err) {
|
||||
throw new Error(err.message);
|
||||
} else {
|
||||
throw new Error('SDK should return a package when there is a new update');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
NewUpdateTest.displayName = 'NewUpdateTest';
|
||||
|
||||
module.exports = NewUpdateTest;
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 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 React = require('react-native');
|
||||
var CodePushSdk = require('react-native-code-push');
|
||||
var NativeBridge = require('react-native').NativeModules.CodePush;
|
||||
var RCTTestModule = require('NativeModules').TestModule;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var NoRemotePackageTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp();
|
||||
this.runTest();
|
||||
}
|
||||
},
|
||||
|
||||
setUp() {
|
||||
var mockAcquisitionSdk = {
|
||||
latestPackage: null,
|
||||
queryUpdateWithCurrentPackage: function(queryPackage, callback){
|
||||
if (!this.latestPackage || queryPackage.appVersion !== this.latestPackage.appVersion ||
|
||||
queryPackage.packageHash == this.latestPackage.packageHash) {
|
||||
callback(/*err:*/ null, false);
|
||||
} else {
|
||||
callback(/*err:*/ null, latestPackage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var mockConfiguration = { appVersion : "1.5.0" };
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
|
||||
},
|
||||
|
||||
runTest() {
|
||||
CodePushSdk.queryUpdate((err, update) => {
|
||||
if (update) {
|
||||
throw new Error('SDK should not return a package if remote does not contain a package');
|
||||
} else if (err) {
|
||||
throw new Error(err.message);
|
||||
} else {
|
||||
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
NoRemotePackageTest.displayName = 'NoRemotePackageTest';
|
||||
|
||||
module.exports = NoRemotePackageTest;
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 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 React = require('react-native');
|
||||
var RCTTestModule = React.NativeModules.TestModule;
|
||||
var CodePushSdk = require('react-native-code-push');
|
||||
var NativeBridge = require('react-native').NativeModules.CodePush;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var NoRemotePackageWithSameAppVersionTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp(this.runTest);
|
||||
}
|
||||
},
|
||||
|
||||
setUp(callWhenDone) {
|
||||
var mockAcquisitionSdk = {
|
||||
latestPackage: {
|
||||
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
},
|
||||
queryUpdateWithCurrentPackage: function(queryPackage, callback){
|
||||
if (!this.latestPackage || queryPackage.appVersion !== this.latestPackage.appVersion ||
|
||||
queryPackage.packageHash == this.latestPackage.packageHash) {
|
||||
callback(/*err:*/ null, false);
|
||||
} else {
|
||||
callback(/*err:*/ null, latestPackage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
var localPackage = JSON.stringify({
|
||||
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.0.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash123",
|
||||
packageSize: 1024
|
||||
});
|
||||
|
||||
var mockConfiguration = { appVersion : "1.0.0" };
|
||||
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
|
||||
NativeBridge.writeToLocalPackage(localPackage, function(err){
|
||||
if (err) {
|
||||
throw new Error('Setup: Error removing local package');
|
||||
} else {
|
||||
callWhenDone();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runTest() {
|
||||
CodePushSdk.queryUpdate((err, update) => {
|
||||
if (update) {
|
||||
throw new Error('SDK should not return a package if remote package is of a different version');
|
||||
} else if (err) {
|
||||
throw new Error(err.message);
|
||||
} else {
|
||||
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
NoRemotePackageWithSameAppVersionTest.displayName = 'NoRemotePackageWithSameAppVersionTest';
|
||||
|
||||
module.exports = NoRemotePackageWithSameAppVersionTest;
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
var React = require('react-native');
|
||||
|
||||
var {
|
||||
AppRegistry,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var TESTS = [
|
||||
require('./NoRemotePackageTest'),
|
||||
require('./NoRemotePackageWithSameAppVersionTest'),
|
||||
require('./FirstUpdateTest'),
|
||||
require('./NewUpdateTest'),
|
||||
require('./SamePackageTest')
|
||||
];
|
||||
|
||||
TESTS.forEach(
|
||||
(test) => AppRegistry.registerComponent(test.displayName, () => test)
|
||||
);
|
||||
|
||||
var QueryUpdateTestApp = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
test: null,
|
||||
};
|
||||
},
|
||||
render: function() {
|
||||
if (this.state.test) {
|
||||
return (
|
||||
<ScrollView>
|
||||
<this.state.test />
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.row}>
|
||||
Click on a test to run it in this shell for easier debugging and
|
||||
development. Run all tests in the testing environment with cmd+U in
|
||||
Xcode.
|
||||
</Text>
|
||||
<View style={styles.separator} />
|
||||
<ScrollView>
|
||||
{TESTS.map((test) => [
|
||||
<TouchableOpacity
|
||||
onPress={() => this.setState({test})}
|
||||
style={styles.row}>
|
||||
<Text style={styles.testName}>
|
||||
{test.displayName}
|
||||
</Text>
|
||||
</TouchableOpacity>,
|
||||
<View style={styles.separator} />
|
||||
])}
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
backgroundColor: 'white',
|
||||
marginTop: 40,
|
||||
margin: 15,
|
||||
},
|
||||
row: {
|
||||
padding: 10,
|
||||
},
|
||||
testName: {
|
||||
fontWeight: '500',
|
||||
},
|
||||
separator: {
|
||||
height: 1,
|
||||
backgroundColor: '#bbbbbb',
|
||||
}
|
||||
});
|
||||
|
||||
AppRegistry.registerComponent('QueryUpdateTestApp', () => QueryUpdateTestApp);
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = React;
|
||||
|
||||
var SamePackageTest = React.createClass({
|
||||
propTypes: {
|
||||
shouldThrow: React.PropTypes.bool,
|
||||
waitOneFrame: React.PropTypes.bool,
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
done: false,
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.waitOneFrame) {
|
||||
requestAnimationFrame(this.runTest);
|
||||
} else {
|
||||
this.setUp(this.runTest);
|
||||
}
|
||||
},
|
||||
|
||||
setUp(callWhenDone) {
|
||||
var mockAcquisitionSdk = {
|
||||
latestPackage: {
|
||||
downloadUrl: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
},
|
||||
queryUpdateWithCurrentPackage: function(queryPackage, callback){
|
||||
if (!this.latestPackage || queryPackage.appVersion !== this.latestPackage.appVersion ||
|
||||
queryPackage.packageHash == this.latestPackage.packageHash) {
|
||||
callback(/*err:*/ null, false);
|
||||
} else {
|
||||
callback(/*err:*/ null, this.latestPackage);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var localPackage = JSON.stringify({
|
||||
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
||||
description: "Angry flappy birds",
|
||||
appVersion: "1.5.0",
|
||||
label: "2.4.0",
|
||||
isMandatory: false,
|
||||
isAvailable: true,
|
||||
updateAppVersion: false,
|
||||
packageHash: "hash240",
|
||||
packageSize: 1024
|
||||
});
|
||||
|
||||
var mockConfiguration = { appVersion : "1.5.0" };
|
||||
NativeBridge.setUsingTestFolder(true);
|
||||
CodePushSdk.setUpTestDependencies(mockAcquisitionSdk, mockConfiguration, NativeBridge);
|
||||
|
||||
NativeBridge.writeToLocalPackage(localPackage, function(err){
|
||||
if (err) {
|
||||
throw new Error('Setup: Error removing local package');
|
||||
} else {
|
||||
callWhenDone();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
runTest() {
|
||||
CodePushSdk.queryUpdate((err, update) => {
|
||||
if (update) {
|
||||
throw new Error('SDK should not return a package when local package is identical');
|
||||
} else if (err) {
|
||||
throw new Error(err.message);
|
||||
} else {
|
||||
this.setState({done: true}, RCTTestModule.markTestCompleted);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
SamePackageTest.displayName = 'SamePackageTest';
|
||||
|
||||
module.exports = SamePackageTest;
|
||||
Reference in New Issue
Block a user