Browse Source

fix android e2e and --release flags, closes #1956

Daniel Zlotin 6 years ago
parent
commit
b850e46357

+ 8
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

6
 import android.support.test.uiautomator.By;
6
 import android.support.test.uiautomator.By;
7
 import android.view.KeyEvent;
7
 import android.view.KeyEvent;
8
 
8
 
9
+import org.junit.Assume;
9
 import org.junit.Test;
10
 import org.junit.Test;
10
 
11
 
11
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
12
 import static android.support.test.InstrumentationRegistry.getInstrumentation;
60
 
61
 
61
 	@Test
62
 	@Test
62
 	public void pressingMenuOpensDevMenu() throws Exception {
63
 	public void pressingMenuOpensDevMenu() throws Exception {
64
+		Assume.assumeTrue(isDebug());
63
 		device().pressKeyCode(KeyEvent.KEYCODE_MENU);
65
 		device().pressKeyCode(KeyEvent.KEYCODE_MENU);
64
 		assertExists(By.text("Debug JS Remotely"));
66
 		assertExists(By.text("Debug JS Remotely"));
65
 	}
67
 	}
66
 
68
 
67
 	@Test
69
 	@Test
68
 	public void pressingRTwiceInSuccessionReloadsReactNative() throws Exception {
70
 	public void pressingRTwiceInSuccessionReloadsReactNative() throws Exception {
71
+		Assume.assumeTrue(isDebug());
72
+
69
 		elementByText("PUSH").click();
73
 		elementByText("PUSH").click();
70
 		assertExists(By.text("Pushed Screen"));
74
 		assertExists(By.text("Pushed Screen"));
71
 
75
 
77
 
81
 
78
 	@Test
82
 	@Test
79
 	public void pressingRTwiceWithDelayDoesNothing() throws Exception {
83
 	public void pressingRTwiceWithDelayDoesNothing() throws Exception {
84
+		Assume.assumeTrue(isDebug());
85
+
80
 		elementByText("PUSH").click();
86
 		elementByText("PUSH").click();
81
 		assertExists(By.text("Pushed Screen"));
87
 		assertExists(By.text("Pushed Screen"));
82
 
88
 
88
 
94
 
89
 	@Test
95
 	@Test
90
 	public void sendingReloadBroadcastReloadsReactNative() throws Exception {
96
 	public void sendingReloadBroadcastReloadsReactNative() throws Exception {
97
+		Assume.assumeTrue(isDebug());
98
+
91
 		elementByText("PUSH").click();
99
 		elementByText("PUSH").click();
92
 		assertExists(By.text("Pushed Screen"));
100
 		assertExists(By.text("Pushed Screen"));
93
 
101
 

+ 7
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/BaseTest.java View File

1
 package com.reactnativenavigation.e2e.androide2e;
1
 package com.reactnativenavigation.e2e.androide2e;
2
 
2
 
3
+import android.content.pm.ApplicationInfo;
4
+import android.content.pm.PackageInfo;
3
 import android.graphics.Bitmap;
5
 import android.graphics.Bitmap;
4
 import android.graphics.BitmapFactory;
6
 import android.graphics.BitmapFactory;
5
 import android.support.test.runner.AndroidJUnit4;
7
 import android.support.test.runner.AndroidJUnit4;
98
 	public void swipeOpenLeftSideMenu() {
100
 	public void swipeOpenLeftSideMenu() {
99
 		device().swipe(5, 152, 500, 152, 15);
101
 		device().swipe(5, 152, 500, 152, 15);
100
 	}
102
 	}
103
+
104
+	public boolean isDebug() throws Exception {
105
+		PackageInfo packageInfo = getInstrumentation().getTargetContext().getPackageManager().getPackageInfo("com.reactnativenavigation.playground", 0);
106
+		return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
107
+	}
101
 }
108
 }

+ 0
- 1
AndroidE2E/app/src/main/AndroidManifest.xml View File

12
         android:label="@string/app_name"
12
         android:label="@string/app_name"
13
         android:supportsRtl="true"
13
         android:supportsRtl="true"
14
         android:theme="@style/AppTheme">
14
         android:theme="@style/AppTheme">
15
-
16
     </application>
15
     </application>
17
 
16
 
18
 </manifest>
17
 </manifest>

+ 1
- 1
AndroidE2E/build.gradle View File

5
         jcenter()
5
         jcenter()
6
     }
6
     }
7
     dependencies {
7
     dependencies {
8
-        classpath 'com.android.tools.build:gradle:2.3.2'
8
+        classpath 'com.android.tools.build:gradle:2.3.3'
9
 
9
 
10
         // NOTE: Do not place your application dependencies here; they belong
10
         // NOTE: Do not place your application dependencies here; they belong
11
         // in the individual module build.gradle files
11
         // in the individual module build.gradle files

+ 5
- 5
docs/docs/CONTRIBUTING.md View File

108
 | `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
108
 | `npm run clean` | cleans all build directories, stops packager, fixes flakiness by removing watchman cache, etc. |
109
 | `npm run start` | starts the react-native packager for local debugging |
109
 | `npm run start` | starts the react-native packager for local debugging |
110
 | `npm run xcode` | for convenience, opens xcode in this project |
110
 | `npm run xcode` | for convenience, opens xcode in this project |
111
-| `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- release` |
111
+| `npm run install-android`  |  builds playground debug/release version and installs on running android devices/emulators. <br> **Options:** `-- --release` |
112
 | `npm run uninstall-android` | uninstalls playground from running android devices/simulators |
112
 | `npm run uninstall-android` | uninstalls playground from running android devices/simulators |
113
 | `npm run test-js` | runs javascript tests and coverage report |
113
 | `npm run test-js` | runs javascript tests and coverage report |
114
 | `npm run test-watch` | runs javascript tests in watch mode (can also use the provided wallaby config) |
114
 | `npm run test-watch` | runs javascript tests in watch mode (can also use the provided wallaby config) |
115
-| `npm run test-unit-ios` | runs ios unit tests in debug/release <br> **Options:** `-- release` |
116
-| `npm run test-unit-android` | runs android unit tests in debug/release <br> **Options:** `-- release` |
117
-| `npm run test-e2e-ios` | runs the ios e2e suite (with detox) in debug/release |
118
-| `npm run test-e2e-android` | runs the android e2e suite (with uiautomator) in debug/release on running devices/emulators <br> **Options:** `-- [release] [just com.TestClass#testMethod]` |
115
+| `npm run test-unit-ios` | runs ios unit tests in debug/release <br> **Options:** `-- --release` |
116
+| `npm run test-unit-android` | runs android unit tests in debug/release <br> **Options:** `-- --release` |
117
+| `npm run test-e2e-ios` | runs the ios e2e suite (with detox) in debug/release <br> **Options:** `-- --release`|
118
+| `npm run test-e2e-android` | runs the android e2e suite (with uiautomator) in debug/release on running devices/emulators <br> **Options:** `-- [--release] [--just com.TestClass#testMethod]` |
119
 | `npm run test-all` | runs all tests in parallel |
119
 | `npm run test-all` | runs all tests in parallel |
120
 
120
 

+ 1
- 1
scripts/install-android.js View File

1
 const _ = require('lodash');
1
 const _ = require('lodash');
2
 const exec = require('shell-utils').exec;
2
 const exec = require('shell-utils').exec;
3
 
3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5
 
5
 
6
 run();
6
 run();
7
 
7
 

+ 7
- 29
scripts/test.e2e.android.js View File

2
 const _ = require('lodash');
2
 const _ = require('lodash');
3
 const exec = require('shell-utils').exec;
3
 const exec = require('shell-utils').exec;
4
 
4
 
5
-const release = _.includes(process.argv, 'release');
5
+const release = _.includes(process.argv, '--release');
6
 
6
 
7
-// Run just a single test, e.g. npm test-e2e-android -- just com.MyClass#myMethod
8
-const filter = _(process.argv).dropWhile((a) => a !== 'just').take(2).last();
7
+// Run just a single test, e.g. npm test-e2e-android -- --just com.MyClass#myMethod
8
+const filter = _.chain(process.argv).dropWhile((a) => a !== '--just').take(2).last().value();
9
 
9
 
10
 run();
10
 run();
11
 
11
 
12
 function run() {
12
 function run() {
13
   if (process.env.CI) {
13
   if (process.env.CI) {
14
-    console.log(`android e2e is disabled on CI`);
14
+    console.log(`android e2e is disabled on CI until Travis will support x86 emulators or we migrate to our own solution`);
15
   } else {
15
   } else {
16
     assertEnv();
16
     assertEnv();
17
     if (!isDeviceRunning()) {
17
     if (!isDeviceRunning()) {
38
 
38
 
39
 function startEmulator() {
39
 function startEmulator() {
40
   console.log(`Looking for avd...`);
40
   console.log(`Looking for avd...`);
41
-  const avds = exec.execSyncRead(`avdmanager list avd -c`);
41
+  const avds = exec.execSyncRead(`${process.env.ANDROID_HOME}/tools/bin/avdmanager list avd -c`);
42
   const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
42
   const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
43
   if (_.isEmpty(avdName)) {
43
   if (_.isEmpty(avdName)) {
44
     throw new Error(`Launch an android emulator or connect a device`);
44
     throw new Error(`Launch an android emulator or connect a device`);
50
 
50
 
51
 function runTests() {
51
 function runTests() {
52
   exec.execSync(`npm run uninstall-android`);
52
   exec.execSync(`npm run uninstall-android`);
53
-  exec.execSync(`npm run install-android ${release ? '-- release' : ''}`);
53
+  exec.execSync(`npm run install-android ${release ? '-- --release' : ''}`);
54
   const filterParam = filter ? '-Pandroid.testInstrumentationRunnerArguments.class=' + filter : '';
54
   const filterParam = filter ? '-Pandroid.testInstrumentationRunnerArguments.class=' + filter : '';
55
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
55
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
56
+  process.exit(0); // eslint-disable-line
56
 }
57
 }
57
-
58
-// const avdName = 'pixel';
59
-// const sdk = 'android-24';
60
-// const apis = 'default';
61
-// const abi = 'armeabi-v7a';
62
-// const packageName = `system-images;${sdk};${apis};${abi}`;
63
-
64
-// function installEmulator() {
65
-//   exec.execSync(`sdkmanager "emulator"`);
66
-//   exec.execSync(`sdkmanager "${packageName}"`);
67
-//   exec.execSync(`echo no | avdmanager create avd --force --name "${avdName}" --abi "${apis}/${abi}" --package "${packageName}" --device "pixel"`);
68
-//   exec.execSync(`avdmanager list avd`);
69
-// }
70
-
71
-// function launchEmulator() {
72
-//   console.log(`Launching Android Emulator`);
73
-//   exec.execSync(`cd $ANDROID_HOME/tools && ./emulator -skin 1080x1920 -gpu host -no-audio @${avdName}`);
74
-//   exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
75
-// }
76
-
77
-// function killEmulators() {
78
-//   exec.execSync(`adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done`);
79
-// }

+ 1
- 1
scripts/test.e2e.ios.js View File

1
 const _ = require('lodash');
1
 const _ = require('lodash');
2
 const exec = require('shell-utils').exec;
2
 const exec = require('shell-utils').exec;
3
 
3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5
 
5
 
6
 function buildProjForDetox() {
6
 function buildProjForDetox() {
7
   const scheme = release ? `playground_release` : `playground`;
7
   const scheme = release ? `playground_release` : `playground`;

+ 1
- 1
scripts/test.unit.android.js View File

1
 const _ = require('lodash');
1
 const _ = require('lodash');
2
 const exec = require('shell-utils').exec;
2
 const exec = require('shell-utils').exec;
3
 
3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5
 
5
 
6
 run();
6
 run();
7
 
7
 

+ 1
- 1
scripts/test.unit.ios.js View File

1
 const _ = require('lodash');
1
 const _ = require('lodash');
2
 const exec = require('shell-utils').exec;
2
 const exec = require('shell-utils').exec;
3
 
3
 
4
-const release = _.includes(process.argv, 'release');
4
+const release = _.includes(process.argv, '--release');
5
 
5
 
6
 function run() {
6
 function run() {
7
   const conf = release ? `Release` : `Debug`;
7
   const conf = release ? `Release` : `Debug`;

+ 4
- 4
scripts/travis.sh View File

22
 run_f "npm install"
22
 run_f "npm install"
23
 run_f "npm run clean"
23
 run_f "npm run clean"
24
 run_f "npm run test-js"
24
 run_f "npm run test-js"
25
-run_f "npm run test-unit-android -- release"
26
-run_f "npm run test-unit-ios -- release"
27
-run_f "npm run test-e2e-android -- release"
28
-run_f "npm run test-e2e-ios -- release"
25
+run_f "npm run test-unit-android -- --release"
26
+run_f "npm run test-unit-ios -- --release"
27
+run_f "npm run test-e2e-android -- --release"
28
+run_f "npm run test-e2e-ios -- --release"
29
 run_f "npm run release"
29
 run_f "npm run release"