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

Commit ce6ac09

Browse files
author
scottbommarito
authored
Merge pull request #357 from Microsoft/automated-testing
ADD AUTOMATED TESTING
2 parents c861d0c + 1b5694e commit ce6ac09

File tree

1,697 files changed

+304953
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,697 files changed

+304953
-14
lines changed

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ build/Release
7373

7474
# Dependency directory
7575
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
76-
node_modules
76+
node_modules/*
77+
#remove /* after plugin-testing-framework is checked into npm
7778

7879
# Xcode
7980
#
@@ -146,4 +147,10 @@ proguard/
146147
.navigation/
147148

148149
# Android Studio captures folder
149-
captures/
150+
captures/
151+
152+
# DELETE THIS AFTER PLUGIN TESTING FRAMEWORK IS ON NPM
153+
# ALSO SEE THE node_modules/* above
154+
!node_modules/
155+
!node_modules/code-push-plugin-testing-framework/
156+
!node_modules/code-push-plugin-testing-framework/*

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ npm-debug.log
2828

2929
# Don't publish example apps
3030
Examples/
31-
Recipes/
31+
Recipes/
32+
33+
# Don't publish compiled testing code
34+
bin/

CONTRIBUTING.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Contributing
2+
3+
## Using the plugin
4+
5+
### Environment setup
6+
7+
`node.js` and `npm` are needed for using this project. `npm` comes bundled with the `node.js` installer. You can download the `node.js` installer here: https://nodejs.org/download/.
8+
9+
Once you have installed `node.js` and `npm`, install the dev dependencies for the project.
10+
11+
```
12+
npm install
13+
```
14+
15+
### Using the plugin manually
16+
17+
Follow these steps to test your modifications to the plugin manually:
18+
- clone this repository
19+
- install the dependencies
20+
21+
Navigate to the root folder from your command line console and run:
22+
```
23+
npm install
24+
```
25+
- install the plugin in a React-Native project
26+
27+
Navigate to the root folder of your React-Native project from your command line console and run:
28+
```
29+
npm install local_path_to_your_clone_of_this_repo
30+
```
31+
- configure the plugin using the steps in the README.md
32+
- build and run your app on an emulator or device
33+
34+
## Test
35+
36+
### Environment setup
37+
38+
First, make sure you have installed the dependencies for the plugin by following the steps above.
39+
40+
Then, make sure you have installed `gulp`.
41+
42+
```
43+
npm install -g gulp
44+
```
45+
46+
To run Android tests, make sure you have `sdk\tools` and `sdk\platform-tools` in your PATH.
47+
48+
To run iOS tests, make sure you've installed CocoaPods and have `.gem/bin` in your PATH.
49+
50+
### Supported platforms
51+
52+
The plugin has end to end tests for Android and iOS. Depending on your development machine OS, you can run some or all the tests.
53+
54+
OS | Supported tests
55+
------------- | -------------
56+
OS X | Android, iOS
57+
Windows | Android
58+
59+
### Test descriptions
60+
61+
The tests first build the app.
62+
63+
They then check if the required emulators are currently running.
64+
65+
If an Android emulator is not running, it attempts to boot an Android emulator named `emulator`. You can specify an emulator by adding `--androidemu yourEmulatorNameHere` as a command line option to the gulp task.
66+
67+
If an iOS simulator is not running, it attempts to boot the latest iOS iPhone simulator. You can specify a simulator by adding `--iosemu yourSimulatorNameHere` as a command line option to the gulp task.
68+
69+
If all the required emulators are not running and the tests fail to boot them, the tests will fail.
70+
71+
If you would like the tests to always restart the necessary emulators (killing them if they are currently running), add a `--clean` flag to the command.
72+
73+
The desired unit tests are then run.
74+
75+
If you would like to skip building, add a `-fast` to the end of the command you'd like to run. For example, `gulp test-ios` becomes `gulp test-ios-fast`.
76+
77+
There is a both a full unit test suite and a "core" set of unit tests that you may run. If you would like to run only the core tests, add a `--core` flag to the command.
78+
79+
If you would like to pull the plugin from NPM rather than running the tests on the local version, add a `--npm` flag to the command.
80+
81+
If you add a `--report` flag to the command, the mocha reporter outputs individual results files for each platform. These are `./test_android.xml`, `./test-ios-ui.xml`, and `./test-ios-wk.xml`.
82+
83+
#### Default
84+
85+
To run all of the unit tests on Android and iOS:
86+
```
87+
gulp test
88+
```
89+
90+
#### iOS
91+
92+
To run all of the unit tests on iOS:
93+
```
94+
gulp test-ios
95+
```
96+
97+
#### Android
98+
99+
To run all of the unit tests on Android:
100+
```
101+
gulp test-android
102+
```
103+
104+
#### More examples
105+
106+
All possible testing configurations have tasks!
107+
108+
The platforms are ordered as follows, and ran in that order:
109+
android, ios
110+
111+
To run the core unit tests on Android:
112+
```
113+
gulp test-android --core
114+
```
115+
116+
To run all of the unit tests on iOS and pull the plugin from NPM:
117+
```
118+
gulp test-ios --npm
119+
```
120+
121+
To run all of the unit tests on Android and iOS without building first:
122+
```
123+
gulp test-fast
124+
```
125+
126+
To run all of the unit tests on iOS and restart the emulators:
127+
```
128+
gulp test-ios --clean
129+
```
130+
131+
To run the core unit tests on Android and pull the plugin from NPM:
132+
```
133+
gulp test-android --core --npm
134+
```
135+
136+
...and so on!

CodePush.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,15 @@ if (NativeCodePush) {
423423
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
424424
},
425425
SyncStatus: {
426-
CHECKING_FOR_UPDATE: 0,
427-
AWAITING_USER_ACTION: 1,
428-
DOWNLOADING_PACKAGE: 2,
429-
INSTALLING_UPDATE: 3,
430-
UP_TO_DATE: 4, // The running app is up-to-date
431-
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
432-
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
433-
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress.
434-
UNKNOWN_ERROR: -1
426+
UP_TO_DATE: 0, // The running app is up-to-date
427+
UPDATE_INSTALLED: 1, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
428+
UPDATE_IGNORED: 2, // The app had an optional update and the end-user chose to ignore it
429+
UNKNOWN_ERROR: 3,
430+
SYNC_IN_PROGRESS: 4, // There is an ongoing "sync" operation in progress.
431+
CHECKING_FOR_UPDATE: 5,
432+
AWAITING_USER_ACTION: 6,
433+
DOWNLOADING_PACKAGE: 7,
434+
INSTALLING_UPDATE: 8
435435
},
436436
UpdateState: {
437437
RUNNING: NativeCodePush.codePushUpdateStateRunning,

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class CodePush implements ReactPackage {
7575
private String appVersion;
7676
private int buildVersion;
7777
private String deploymentKey;
78-
private final String serverUrl = "https://codepush.azurewebsites.net/";
78+
private String serverUrl = "https://codepush.azurewebsites.net/";
7979

8080
private Activity mainActivity;
8181
private Context applicationContext;
@@ -110,6 +110,12 @@ public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode
110110
initializeUpdateAfterRestart();
111111
}
112112

113+
// USED FOR TESTING SO THAT IT CAN CONNECT TO DEBUG SERVER
114+
public CodePush(String deploymentKey, Activity mainActivity, boolean isDebugMode, String serverUrl) {
115+
this(deploymentKey, mainActivity, isDebugMode);
116+
this.serverUrl = serverUrl;
117+
}
118+
113119
private void clearDebugCacheIfNeeded() {
114120
if (isDebugMode && isPendingUpdate(null)) {
115121
// This needs to be kept in sync with https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManager.java#L78
@@ -506,6 +512,10 @@ public void dispatchDownloadProgressEvent() {
506512
e.printStackTrace();
507513
saveFailedUpdate(updatePackage);
508514
promise.reject(e);
515+
} catch (CodePushMalformedDataException e) {
516+
e.printStackTrace();
517+
saveFailedUpdate(updatePackage);
518+
promise.reject(e);
509519
}
510520

511521
return null;

0 commit comments

Comments
 (0)