Daniel Zlotin 7 years ago
parent
commit
db04a52e4a
3 changed files with 43 additions and 6 deletions
  1. 2
    0
      .travis.yml
  2. 4
    0
      scripts/env/installAppleSimUtils.sh
  3. 37
    6
      scripts/test.e2e.android.js

+ 2
- 0
.travis.yml View File

@@ -26,6 +26,8 @@ install:
26 26
   - source ./scripts/env/installNode.sh
27 27
         # android sdk:
28 28
   - source ./scripts/env/installAndroidSDK.sh
29
+        # AppleSimUtils
30
+  - source ./scripts/env/installAppleSimUtils.sh
29 31
 
30 32
 script:
31 33
   - set -e

+ 4
- 0
scripts/env/installAppleSimUtils.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/bash -e
2
+
3
+brew tap wix/brew
4
+brew install --HEAD applesimutils

+ 37
- 6
scripts/test.e2e.android.js View File

@@ -2,12 +2,6 @@
2 2
 const _ = require('lodash');
3 3
 const exec = require('shell-utils').exec;
4 4
 
5
-// const avdName = 'pixel';
6
-// const sdk = 'android-24';
7
-// const apis = 'default';
8
-// const abi = 'armeabi-v7a';
9
-// const packageName = `system-images;${sdk};${apis};${abi}`;
10
-
11 5
 const release = _.includes(process.argv, 'release');
12 6
 
13 7
 // Run just a single test, e.g. npm test-e2e-android -- just com.MyClass#myMethod
@@ -19,10 +13,41 @@ function run() {
19 13
   if (process.env.CI) {
20 14
     console.log(`android e2e is disabled on CI`);
21 15
   } else {
16
+    assertEnv();
17
+    if (!isDeviceRunning()) {
18
+      startEmulator();
19
+    }
22 20
     runTests();
23 21
   }
24 22
 }
25 23
 
24
+function assertEnv() {
25
+  if (_.isEmpty(process.env.ANDROID_HOME)) {
26
+    throw new Error(`$ANDROID_HOME is not defined`);
27
+  }
28
+}
29
+
30
+function isDeviceRunning() {
31
+  try {
32
+    const response = exec.execSyncRead(`adb -e shell getprop init.svc.bootanim 2>&1`);
33
+    return _.isEqual(response, `stopped`);
34
+  } catch (err) {
35
+    return false;
36
+  }
37
+}
38
+
39
+function startEmulator() {
40
+  console.log(`Looking for avd...`);
41
+  const avds = exec.execSyncRead(`avdmanager list avd -c`);
42
+  const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
43
+  if (_.isEmpty(avdName)) {
44
+    throw new Error(`Launch an android emulator or connect a device`);
45
+  }
46
+  console.log(`found avd name: ${avdName}, Launching...`);
47
+  exec.execAsyncSilent(`${process.env.ANDROID_HOME}/tools/emulator -gpu host -no-audio @${avdName}`);
48
+  exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
49
+}
50
+
26 51
 function runTests() {
27 52
   exec.execSync(`npm run uninstall-android`);
28 53
   exec.execSync(`npm run install-android ${release ? '-- release' : ''}`);
@@ -30,6 +55,12 @@ function runTests() {
30 55
   exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
31 56
 }
32 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
+
33 64
 // function installEmulator() {
34 65
 //   exec.execSync(`sdkmanager "emulator"`);
35 66
 //   exec.execSync(`sdkmanager "${packageName}"`);