Repository: wix/Detox
Pull request #2045 (2020-05-07 11:34:34)

Apply missing flags to "pm install": reinstall, permissions, test
- [x] This is a small change 
- [ ] This change has been discussed in issue #2019 and the solution has been agreed upon with maintainers.

---

**Description:**
Add missing flags to recently instated `adb shell pm install` command (see #2019) - the same ones as used to be specified for `adb install`:
- `-r` to allow for the replacement of existing apps (hence no need to manually uninstall)
- `-t` to allow for test packages (seems useless, but nevertheless)
- `-g` to auto-allow for all runtime permissions.

This doesn't fix any reported issue in particular, but rather addresses [this comment](https://github.com/wix/Detox/pull/2019#issuecomment-623632126) in the original PR.


Patch:
diff --git a/detox/runners/jest/SpecReporterCircus.js b/detox/runners/jest/SpecReporterCircus.js
index cade356a4..d94c44142 100644
--- a/detox/runners/jest/SpecReporterCircus.js
+++ b/detox/runners/jest/SpecReporterCircus.js
@@ -22,10 +22,8 @@ class SpecReporterCircus extends CircusTestEventListenerBase {
   }
 
   _onTestStart(event) {
-    const { test } = event;
     this._specReporter.onTestStart({
-      description: test.name,
-      invocations: test.invocations,
+      description: event.test.name,
     });
   }
 
@@ -33,7 +31,6 @@ class SpecReporterCircus extends CircusTestEventListenerBase {
     const { test } = event;
     const testInfo = {
       description: test.name,
-      invocations: test.invocations,
     };
     this._specReporter.onTestEnd(testInfo, test.errors.length ? 'failed' : 'success');
   }
diff --git a/detox/runners/jest/SpecReporterImpl.js b/detox/runners/jest/SpecReporterImpl.js
index af9ba1fb7..ec8ce1171 100644
--- a/detox/runners/jest/SpecReporterImpl.js
+++ b/detox/runners/jest/SpecReporterImpl.js
@@ -29,12 +29,12 @@ class SpecReporter extends ReporterBase {
     }
   }
 
-  onTestStart({description, invocations = 1}) {
-    this._traceTest({description, invocations});
+  onTestStart({description}) {
+    this._traceTest({description});
   }
 
-  onTestEnd({description, invocations = 1}, result) {
-    let status;
+  onTestEnd({description}, result) {
+    let status = '';
     switch (result) {
       case 'skipped': status = RESULT_SKIPPED; break;
       case 'failed': status = RESULT_FAILED; break;
@@ -42,7 +42,7 @@ class SpecReporter extends ReporterBase {
       case 'success': status = RESULT_SUCCESS; break;
       default: status = RESULT_OTHER; break;
     }
-    this._traceTest({description, invocations}, status);
+    this._traceTest({description}, status);
   }
 
   _regenerateSuitesDesc() {
@@ -58,11 +58,8 @@ class SpecReporter extends ReporterBase {
     this._suitesDesc = chalk.bold.white(this._suitesDesc);
   }
 
-  _traceTest({description, invocations}, _status = undefined) {
-    const testDescription = chalk.gray(description);
-    const retriesDescription = (invocations > 1) ? chalk.gray(` [Retry #${invocations - 1}]`) : '';
-    const status = chalk.gray(_status ? ` [${_status}]` : '');
-    const desc = this._suitesDesc + testDescription + retriesDescription + status;
+  _traceTest({description}, status) {
+    const desc = this._suitesDesc + chalk.gray(description) + chalk.gray(status ? ` [${status}]` : '');
     log.info({event: 'SPEC_STATE_CHANGE'}, desc);
   }
 }
diff --git a/detox/src/devices/drivers/android/AndroidDriver.js b/detox/src/devices/drivers/android/AndroidDriver.js
index 8aaab8e0d..a3b8909c6 100644
--- a/detox/src/devices/drivers/android/AndroidDriver.js
+++ b/detox/src/devices/drivers/android/AndroidDriver.js
@@ -84,11 +84,6 @@ class AndroidDriver extends DeviceDriverBase {
     await uninstallHelper.uninstall(deviceId, bundleId);
   }
 
-  async uninstallAppByApk(deviceId, apkPath) {
-    const bundleId = await this.getBundleIdFromBinary(apkPath);
-    await this.uninstallApp(deviceId, bundleId);
-  }
-
   async launchApp(deviceId, bundleId, launchArgs, languageAndLocale) {
     await this.emitter.emit('beforeLaunchApp', { deviceId, bundleId, launchArgs });
 
diff --git a/detox/src/devices/drivers/android/EmulatorDriver.js b/detox/src/devices/drivers/android/EmulatorDriver.js
index 96b17fe70..debaf43d0 100644
--- a/detox/src/devices/drivers/android/EmulatorDriver.js
+++ b/detox/src/devices/drivers/android/EmulatorDriver.js
@@ -73,8 +73,6 @@ class EmulatorDriver extends AndroidDriver {
       testBinaryPath,
     } = this._getInstallPaths(_binaryPath, _testBinaryPath);
 
-    await this.uninstallAppByApk(deviceId, binaryPath);
-
     const installHelper = new AppInstallHelper(this.adb);
     await installHelper.install(deviceId, binaryPath, testBinaryPath);
   }
diff --git a/detox/src/devices/drivers/android/tools/ADB.js b/detox/src/devices/drivers/android/tools/ADB.js
index 44bf9856d..fbfda0ed3 100644
--- a/detox/src/devices/drivers/android/tools/ADB.js
+++ b/detox/src/devices/drivers/android/tools/ADB.js
@@ -105,7 +105,7 @@ class ADB {
   }
 
   /*async*/ remoteInstall(deviceId, path) {
-    return this.shell(deviceId, `pm install ${path}`);
+    return this.shell(deviceId, `pm install -r -g -t ${path}`);
   }
 
   async uninstall(deviceId, appId) {


Test patch:
diff --git a/detox/src/devices/drivers/android/tools/ADB.test.js b/detox/src/devices/drivers/android/tools/ADB.test.js
index f6a6e7d81..3d70003f8 100644
--- a/detox/src/devices/drivers/android/tools/ADB.test.js
+++ b/detox/src/devices/drivers/android/tools/ADB.test.js
@@ -180,7 +180,7 @@ describe('ADB', () => {
     await adb.remoteInstall(deviceId, binaryPath);
 
     expect(exec).toHaveBeenCalledWith(
-      expect.stringContaining(`-s mockEmulator shell "pm install ${binaryPath}"`),
+      expect.stringContaining(`-s mockEmulator shell "pm install -r -g -t ${binaryPath}"`),
       undefined, undefined, expect.anything());
   });