mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 23:59:42 +08:00
wrote QueryUpdate and ApplyUpdate tests
This commit is contained in:
@@ -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