Skip to content

Commit 352995d

Browse files
authored
[Tests] Use env in scripts and update docs (#1788)
1 parent f95194f commit 352995d

File tree

5 files changed

+38
-41
lines changed

5 files changed

+38
-41
lines changed

CONTRIBUTING.md

+17-19
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ Follow these steps to test your modifications to the plugin manually:
3737

3838
First, make sure you have installed the dependencies for the plugin by following the steps above.
3939

40-
Then, make sure you have installed `gulp`.
40+
Then, make sure you have installed `react-native-cli`.
4141

4242
```
43-
npm install -g gulp
43+
npm install -g react-native-cli
4444
```
4545

46-
To run Android tests, make sure you have `sdk\tools` and `sdk\platform-tools` in your PATH.
46+
To run Android tests, make sure you have `sdk\tools`, `sdk\emulator` and `sdk\platform-tools` in your PATH.
4747

4848
To run iOS tests, make sure you've installed CocoaPods and have `.gem/bin` in your PATH.
4949

@@ -62,43 +62,41 @@ The tests first build the app.
6262

6363
They then check if the required emulators are currently running.
6464

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.
65+
If an Android emulator is not running, it attempts to boot the latest Android emulator. You can specify an emulator by adding env variable `ANDROID_EMU=yourEmulatorNameHere` to the npm command. For example: `ANDROID_EMU=yourEmulatorNameHere npm run test:android`.
6666

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.
67+
If an iOS simulator is not running, it attempts to boot the latest iOS iPhone simulator. You can specify a simulator by adding env variable `IOS_EMU=yourSimulatorNameHere` to the npm command. For example: `IOS_EMU="iPhone 8 (0567DFF8-329E-41A3-BD6D-E48E9DD5EF39)" npm run test:ios`.
6868

6969
If all the required emulators are not running and the tests fail to boot them, the tests will fail.
7070

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.
71+
If you would like the tests to always restart the necessary emulators (killing them if they are currently running), setup a env variable `CLEAN=true` to the command. For example: `CLEAN=true npm run test`.
7272

7373
The desired unit tests are then run.
7474

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`.
75+
If you would like to skip building, add a `:fast` in the command you'd like to run. For example, `npm run test:ios` becomes `npm run test:fast:ios` or `npm run test:android` becomes `npm run test:fast:android`.
7676

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.
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, setup a env variable `CORE=true` to the command. For example: `CORE=true npm run test:android`.
7878

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`.
79+
If you would like to pull the plugin from NPM rather than running the tests on the local version, setup a env variable `NPM=true` to the command. For example: `NPM=true npm run test:ios`.
8280

8381
#### Default
8482

8583
To run all of the unit tests on Android and iOS:
8684
```
87-
gulp test
85+
npm run test
8886
```
8987

9088
#### iOS
9189

9290
To run all of the unit tests on iOS:
9391
```
94-
gulp test-ios
92+
npm run test:ios
9593
```
9694

9795
#### Android
9896

9997
To run all of the unit tests on Android:
10098
```
101-
gulp test-android
99+
npm run test:android
102100
```
103101

104102
#### More examples
@@ -110,27 +108,27 @@ android, ios
110108

111109
To run the core unit tests on Android:
112110
```
113-
gulp test-android --core
111+
CORE=true npm run test:android
114112
```
115113

116114
To run all of the unit tests on iOS and pull the plugin from NPM:
117115
```
118-
gulp test-ios --npm
116+
NPM=true npm run test:ios
119117
```
120118

121119
To run all of the unit tests on Android and iOS without building first:
122120
```
123-
gulp test-fast
121+
npm run test:fast
124122
```
125123

126124
To run all of the unit tests on iOS and restart the emulators:
127125
```
128-
gulp test-ios --clean
126+
CLEAN=true npm run test:ios
129127
```
130128

131129
To run the core unit tests on Android and pull the plugin from NPM:
132130
```
133-
gulp test-android --core --npm
131+
NPM=true CORE=true npm run test:android
134132
```
135133

136134
...and so on!

code-push-plugin-testing-framework/script/platform.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Android = (function () {
2828
*/
2929
Android.prototype.getServerUrl = function () {
3030
if (!this.serverUrl)
31-
this.serverUrl = testUtil_1.TestUtil.readMochaCommandLineOption(Android.ANDROID_SERVER_URL_OPTION_NAME, Android.DEFAULT_ANDROID_SERVER_URL);
31+
this.serverUrl = process.env.ANDROID_SERVER ? process.env.ANDROID_SERVER : Android.DEFAULT_ANDROID_SERVER_URL;
3232
return this.serverUrl;
3333
};
3434
/**
@@ -43,7 +43,6 @@ var Android = (function () {
4343
Android.prototype.getDefaultDeploymentKey = function () {
4444
return "mock-android-deployment-key";
4545
};
46-
Android.ANDROID_SERVER_URL_OPTION_NAME = "--androidserver";
4746
Android.DEFAULT_ANDROID_SERVER_URL = "http://10.0.2.2:3001";
4847
return Android;
4948
}());
@@ -73,7 +72,8 @@ var IOS = (function () {
7372
*/
7473
IOS.prototype.getServerUrl = function () {
7574
if (!this.serverUrl)
76-
this.serverUrl = testUtil_1.TestUtil.readMochaCommandLineOption(IOS.IOS_SERVER_URL_OPTION_NAME, IOS.DEFAULT_IOS_SERVER_URL);
75+
this.serverUrl = process.env.IOS_SERVER ? process.env.IOS_SERVER : IOS.DEFAULT_IOS_SERVER_URL;
76+
7777
return this.serverUrl;
7878
};
7979
/**
@@ -88,7 +88,6 @@ var IOS = (function () {
8888
IOS.prototype.getDefaultDeploymentKey = function () {
8989
return "mock-ios-deployment-key";
9090
};
91-
IOS.IOS_SERVER_URL_OPTION_NAME = "--iosserver";
9291
IOS.DEFAULT_IOS_SERVER_URL = "http://127.0.0.1:3000";
9392
return IOS;
9493
}());
@@ -172,7 +171,7 @@ var AndroidEmulatorManager = (function () {
172171
return Q(this.targetEmulator);
173172
else {
174173
const deferred = Q.defer();
175-
const targetAndroidEmulator = testUtil_1.TestUtil.readMochaCommandLineOption(AndroidEmulatorManager.ANDROID_EMULATOR_OPTION_NAME);
174+
const targetAndroidEmulator = process.env.ANDROID_EMU;
176175
if (!targetAndroidEmulator) {
177176
// If no Android simulator is specified, get the most recent Android simulator to run tests on.
178177
testUtil_1.TestUtil.getProcessOutput("emulator -list-avds", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
@@ -280,7 +279,6 @@ var AndroidEmulatorManager = (function () {
280279
AndroidEmulatorManager.prototype.uninstallApplication = function (appId) {
281280
return commandWithCheckAppExistence("adb uninstall", appId);
282281
};
283-
AndroidEmulatorManager.ANDROID_EMULATOR_OPTION_NAME = "--androidemu";
284282
return AndroidEmulatorManager;
285283
}());
286284
exports.AndroidEmulatorManager = AndroidEmulatorManager;
@@ -296,7 +294,7 @@ var IOSEmulatorManager = (function () {
296294
return Q(this.targetEmulator);
297295
else {
298296
let deferred = Q.defer();
299-
let targetIOSEmulator = testUtil_1.TestUtil.readMochaCommandLineOption(IOSEmulatorManager.IOS_EMULATOR_OPTION_NAME);
297+
let targetIOSEmulator = process.env.IOS_EMU;
300298
if (!targetIOSEmulator) {
301299
// If no iOS simulator is specified, get the most recent iOS simulator to run tests on.
302300
testUtil_1.TestUtil.getProcessOutput("xcrun simctl list", { noLogCommand: true, noLogStdOut: true, noLogStdErr: true })
@@ -395,7 +393,6 @@ var IOSEmulatorManager = (function () {
395393
IOSEmulatorManager.prototype.uninstallApplication = function (appId) {
396394
return testUtil_1.TestUtil.getProcessOutput("xcrun simctl uninstall booted " + appId).then(function () { return null; });
397395
};
398-
IOSEmulatorManager.IOS_EMULATOR_OPTION_NAME = "--iosemu";
399396
return IOSEmulatorManager;
400397
}());
401398
exports.IOSEmulatorManager = IOSEmulatorManager;

code-push-plugin-testing-framework/script/testConfig.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@ var TestUtil_1 = require("./TestUtil");
77
// Configuration variables.
88
// What plugin to use, what project directories to use, etc.
99
// COMMAND LINE OPTION NAMES, FLAGS, AND DEFAULTS
10-
var TEST_RUN_DIRECTORY_OPTION_NAME = "--test-directory";
1110
var DEFAULT_TEST_RUN_DIRECTORY = path.join(os.tmpdir(), TestUtil_1.TestUtil.getPluginName(), "test-run");
12-
var TEST_UPDATES_DIRECTORY_OPTION_NAME = "--updates-directory";
1311
var DEFAULT_UPDATES_DIRECTORY = path.join(os.tmpdir(), TestUtil_1.TestUtil.getPluginName(), "updates");
14-
var CORE_TESTS_ONLY_FLAG_NAME = "--core";
15-
var PULL_FROM_NPM_FLAG_NAME = "--npm";
1612
var DEFAULT_PLUGIN_PATH = path.join(__dirname, "../..");
1713
var NPM_PLUGIN_PATH = TestUtil_1.TestUtil.getPluginName();
1814
var SETUP_FLAG_NAME = "--setup";
19-
var RESTART_EMULATORS_FLAG_NAME = "--clean";
2015
var DEFAULT_PLUGIN_TGZ_NAME = TestUtil_1.TestUtil.getPluginName() + "-" + TestUtil_1.TestUtil.getPluginVersion() + ".tgz";
2116
// CONST VARIABLES
2217
exports.TestAppName = "TestCodePush";
2318
exports.TestNamespace = "com.testcodepush";
2419
exports.AcquisitionSDKPluginName = "code-push";
2520
exports.templatePath = path.join(__dirname, "../../test/template");
26-
exports.thisPluginInstallString = TestUtil_1.TestUtil.readMochaCommandLineFlag(PULL_FROM_NPM_FLAG_NAME) ? `npm install ${NPM_PLUGIN_PATH}` : `npm pack ${DEFAULT_PLUGIN_PATH} && npm install ${DEFAULT_PLUGIN_TGZ_NAME}`;
27-
exports.testRunDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_RUN_DIRECTORY_OPTION_NAME, DEFAULT_TEST_RUN_DIRECTORY);
28-
exports.updatesDirectory = TestUtil_1.TestUtil.readMochaCommandLineOption(TEST_UPDATES_DIRECTORY_OPTION_NAME, DEFAULT_UPDATES_DIRECTORY);
29-
exports.onlyRunCoreTests = TestUtil_1.TestUtil.readMochaCommandLineFlag(CORE_TESTS_ONLY_FLAG_NAME);
21+
exports.thisPluginInstallString = TestUtil_1.TestUtil.resolveBooleanVariables(process.env.NPM) ? `npm install ${NPM_PLUGIN_PATH}` : `npm pack ${DEFAULT_PLUGIN_PATH} && npm install ${DEFAULT_PLUGIN_TGZ_NAME}`;
22+
exports.testRunDirectory = process.env.RUN_DIR ? process.env.RUN_DIR: DEFAULT_TEST_RUN_DIRECTORY;
23+
exports.updatesDirectory = process.env.UPDATE_DIR ? process.env.UPDATE_DIR : DEFAULT_UPDATES_DIRECTORY;
24+
exports.onlyRunCoreTests = TestUtil_1.TestUtil.resolveBooleanVariables(process.env.CORE);
3025
exports.shouldSetup = TestUtil_1.TestUtil.readMochaCommandLineFlag(SETUP_FLAG_NAME);
31-
exports.restartEmulators = TestUtil_1.TestUtil.readMochaCommandLineFlag(RESTART_EMULATORS_FLAG_NAME);
26+
exports.restartEmulators = TestUtil_1.TestUtil.resolveBooleanVariables(process.env.CLEAN);

code-push-plugin-testing-framework/script/testUtil.js

+11
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ var TestUtil = (function () {
139139
archive.finalize();
140140
return deferred.promise;
141141
};
142+
143+
/**
144+
* Check that boolean environment variable string is 'true.
145+
*/
146+
TestUtil.resolveBooleanVariables = function(variable) {
147+
if (variable) {
148+
return variable.toLowerCase() === 'true';
149+
}
150+
151+
return false;
152+
}
142153
//// Placeholders
143154
// Used in the template to represent data that needs to be added by the testing framework at runtime.
144155
TestUtil.ANDROID_KEY_PLACEHOLDER = "CODE_PUSH_ANDROID_DEPLOYMENT_KEY";

code-push-plugin-testing-framework/typings/code-push-plugin-testing-framework.d.ts

-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ declare module 'code-push-plugin-testing-framework/script/platform' {
7979
* Runs when the flag is present, doesn't run otherwise.
8080
*/
8181
getCommandLineFlagName(): string;
82-
private static ANDROID_SERVER_URL_OPTION_NAME;
8382
private static DEFAULT_ANDROID_SERVER_URL;
8483
/**
8584
* Gets the server url used for testing.
@@ -110,7 +109,6 @@ declare module 'code-push-plugin-testing-framework/script/platform' {
110109
* Runs when the flag is present, doesn't run otherwise.
111110
*/
112111
getCommandLineFlagName(): string;
113-
private static IOS_SERVER_URL_OPTION_NAME;
114112
private static DEFAULT_IOS_SERVER_URL;
115113
/**
116114
* Gets the server url used for testing.
@@ -126,7 +124,6 @@ declare module 'code-push-plugin-testing-framework/script/platform' {
126124
getDefaultDeploymentKey(): string;
127125
}
128126
export class AndroidEmulatorManager implements IEmulatorManager {
129-
private static ANDROID_EMULATOR_OPTION_NAME;
130127
private targetEmulator;
131128
/**
132129
* Returns the target emulator, which is specified through the command line.
@@ -162,7 +159,6 @@ declare module 'code-push-plugin-testing-framework/script/platform' {
162159
uninstallApplication(appId: string): Q.Promise<void>;
163160
}
164161
export class IOSEmulatorManager implements IEmulatorManager {
165-
private static IOS_EMULATOR_OPTION_NAME;
166162
private targetEmulator;
167163
/**
168164
* Returns the target emulator, which is specified through the command line.

0 commit comments

Comments
 (0)