Repository: wix/Detox
Pull request #3738 (2022-11-27 18:32:17)

[website] Update Android project setup docs on proguardFile
I just went through the website docs on [Project Setup](https://wix.github.io/Detox/docs/introduction/project-setup/) for Android. Everything went smoothly except for the line about the `proguardFile`.

Following the website docs as is, I get an error that says "Project with path ':detox' could not be found in project ':app'". With the proposed change, Gradle is happy. Also, this change brings the website's `proguardFile` docs in line with what I found [here](https://github.com/wix/Detox/blob/master/website/versioned_docs/version-20.x/guide/proguard-configuration.md).


Patch:
diff --git a/.buildkite/jobs/pipeline.android_demo_app_rn_68.yml b/.buildkite/jobs/pipeline.android_demo_app_rn_68.yml
index 746373799..0a82faf7f 100644
--- a/.buildkite/jobs/pipeline.android_demo_app_rn_68.yml
+++ b/.buildkite/jobs/pipeline.android_demo_app_rn_68.yml
@@ -1,7 +1,7 @@
   - label: ":android::react: RN.68 + Android: Demo app"
     command:
       - "nvm install"
-      - "JAVA_HOME=/usr/local/opt/openjdk@11/ ./scripts/demo-projects.android.sh"
+      - "./scripts/demo-projects.android.sh"
     env:
       REACT_NATIVE_VERSION: 0.68.5
       REACT_NATIVE_COMPAT_TEST: true
diff --git a/.buildkite/jobs/pipeline.android_demo_app_rn_69.yml b/.buildkite/jobs/pipeline.android_demo_app_rn_69.yml
index 818ddbc53..7dbb2a7b0 100644
--- a/.buildkite/jobs/pipeline.android_demo_app_rn_69.yml
+++ b/.buildkite/jobs/pipeline.android_demo_app_rn_69.yml
@@ -1,7 +1,7 @@
   - label: ":android::react: RN.69 + Android: Demo app"
     command:
       - "nvm install"
-      - "JAVA_HOME=/usr/local/opt/openjdk@11/ ./scripts/demo-projects.android.sh"
+      - "./scripts/demo-projects.android.sh"
     env:
       REACT_NATIVE_VERSION: 0.69.7
       DETOX_DISABLE_POD_INSTALL: true
diff --git a/.buildkite/jobs/pipeline.android_rn_68.yml b/.buildkite/jobs/pipeline.android_rn_68.yml
index d359840d9..9e116780e 100644
--- a/.buildkite/jobs/pipeline.android_rn_68.yml
+++ b/.buildkite/jobs/pipeline.android_rn_68.yml
@@ -1,7 +1,7 @@
   - label: ":android::detox: RN.68 + Android: Tests app"
     command:
       - "nvm install"
-      - "JAVA_HOME=/usr/local/opt/openjdk@11/ ./scripts/ci.android.sh"
+      - "./scripts/ci.android.sh"
     env:
       REACT_NATIVE_VERSION: 0.68.5
       DETOX_DISABLE_POD_INSTALL: true
diff --git a/.buildkite/jobs/pipeline.android_rn_69.yml b/.buildkite/jobs/pipeline.android_rn_69.yml
index b58100b06..03f75e7e6 100644
--- a/.buildkite/jobs/pipeline.android_rn_69.yml
+++ b/.buildkite/jobs/pipeline.android_rn_69.yml
@@ -1,7 +1,7 @@
   - label: ":android::detox: RN.69 + Android: Tests app"
     command:
       - "nvm install"
-      - "JAVA_HOME=/usr/local/opt/openjdk@11/ ./scripts/ci.android.sh"
+      - "./scripts/ci.android.sh"
     env:
       REACT_NATIVE_VERSION: 0.69.7
       DETOX_DISABLE_POD_INSTALL: true
diff --git a/.buildkite/jobs/pipeline.ios_demo_app_rn_69.yml b/.buildkite/jobs/pipeline.ios_demo_app_rn_69.yml
index baec66e63..e61e6f93c 100644
--- a/.buildkite/jobs/pipeline.ios_demo_app_rn_69.yml
+++ b/.buildkite/jobs/pipeline.ios_demo_app_rn_69.yml
@@ -1,7 +1,7 @@
   - label: ":ios::react: RN.69 + iOS: Demo app"
     command:
       - "nvm install"
-      - "JAVA_HOME=/usr/local/opt/openjdk@11/ ./scripts/demo-projects.ios.sh"
+      - "./scripts/demo-projects.ios.sh"
     env:
       REACT_NATIVE_VERSION: 0.69.7
     artifact_paths:
diff --git a/detox/src/logger/utils/DetoxLogFinalizer.js b/detox/src/logger/utils/DetoxLogFinalizer.js
index 5d56bbd77..06c72d2da 100644
--- a/detox/src/logger/utils/DetoxLogFinalizer.js
+++ b/detox/src/logger/utils/DetoxLogFinalizer.js
@@ -37,7 +37,7 @@ class DetoxLogFinalizer {
       return;
     }
 
-    if (this._areLogsEnabled()) {
+    if (this._shouldSaveLogs()) {
       const rootDir = this._config.artifacts.rootDir;
 
       await fs.mkdirp(rootDir);
@@ -69,14 +69,14 @@ class DetoxLogFinalizer {
       return;
     }
 
-    const logsEnabled = this._areLogsEnabled();
-    const rootDir = logsEnabled ? this._config.artifacts.rootDir : '';
-    if (logsEnabled) {
+    const shouldSaveLogs = this._shouldSaveLogs(true);
+    const rootDir = shouldSaveLogs ? this._config.artifacts.rootDir : '';
+    if (shouldSaveLogs) {
       fs.mkdirpSync(rootDir);
     }
 
     for (const log of logs) {
-      if (logsEnabled) {
+      if (shouldSaveLogs) {
         const dest = path.join(rootDir, path.basename(log));
         this._safeMoveSync(log, dest);
       } else {
@@ -137,7 +137,7 @@ class DetoxLogFinalizer {
   }
 
   /** @private */
-  _areLogsEnabled() {
+  _shouldSaveLogs(isEmergencyExit = false) {
     if (!this._config) {
       return false;
     }
@@ -155,6 +155,10 @@ class DetoxLogFinalizer {
       return true;
     }
 
+    if (isEmergencyExit) {
+      return true;
+    }
+
     return this._session.testResults.some(r => !r.success);
   }
 }
diff --git a/docs/guide/migration.md b/docs/guide/migration.md
index 617453e24..3feb83994 100644
--- a/docs/guide/migration.md
+++ b/docs/guide/migration.md
@@ -239,7 +239,7 @@ See comments line by line:
 
 2\. If you don’t have `maxWorkers: 1` configured, please add it.
 
-3\. If you removed your test environment in the previous step, `testEnvironment` property.
+3\. If you removed your test environment in the previous step, remove the `testEnvironment` property.
 
 4\. Remove `testRunner` since it is already `jest-circus` by default in Jest 27.x and higher.
 
diff --git a/scripts/ci.android.sh b/scripts/ci.android.sh
index 77ecabb21..f7eb7c49c 100755
--- a/scripts/ci.android.sh
+++ b/scripts/ci.android.sh
@@ -28,8 +28,6 @@ fi
 
 mkdir -p coverage
 
-run_f "scripts/ci.genycloud-login.sh"
-
 pushd detox/test
 
 run_f "npm run build:android"
diff --git a/scripts/ci.genycloud-login.sh b/scripts/ci.genycloud-login.sh
deleted file mode 100755
index a4ffe82a4..000000000
--- a/scripts/ci.genycloud-login.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash -ex
-
-which gmsaas
-gmsaas --version
-gmsaas auth login "$GENYCLOUD_USERNAME" "$GENYCLOUD_PASSWORD"
diff --git a/website/versioned_docs/version-20.x/introduction/project-setup.mdx b/website/versioned_docs/version-20.x/introduction/project-setup.mdx
index 3b6730355..240ae7bab 100644
--- a/website/versioned_docs/version-20.x/introduction/project-setup.mdx
+++ b/website/versioned_docs/version-20.x/introduction/project-setup.mdx
@@ -215,7 +215,7 @@ Now let's move on to the next build script and prepare it:
      release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
-+      proguardFile "${project(':detox').projectDir}/proguard-rules-app.pro"
++      proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
 
        signingConfig signingConfigs.release
      }


Test patch:
diff --git a/detox/src/logger/utils/DetoxLogFinalizer.test.js b/detox/src/logger/utils/DetoxLogFinalizer.test.js
index 53012497b..689f2f674 100644
--- a/detox/src/logger/utils/DetoxLogFinalizer.test.js
+++ b/detox/src/logger/utils/DetoxLogFinalizer.test.js
@@ -172,21 +172,10 @@ describe('DetoxLogFinalizer', () => {
       expect(fs.existsSync(temporaryFiles[2])).toBe(false);
     });
 
-    it('should not create logs for successful run when configured', async () => {
+    it('should create logs even for successful run when configured to keep failing logs', async () => {
       session.detoxConfig.artifacts.plugins.log.keepOnlyFailedTestsArtifacts = true;
       session.testResults = [{ success: true }];
 
-      await createLogFiles();
-      finalizer.finalizeSync();
-      expect(fs.existsSync(artifactsDir())).toBe(false);
-      expect(fs.existsSync(temporaryFiles[1])).toBe(false);
-      expect(fs.existsSync(temporaryFiles[2])).toBe(false);
-    });
-
-    it('should create logs for failing run when configured', async () => {
-      session.detoxConfig.artifacts.plugins.log.keepOnlyFailedTestsArtifacts = true;
-      session.testResults = [{ success: false }];
-
       await createLogFiles();
       finalizer.finalizeSync();
 
@@ -195,6 +184,10 @@ describe('DetoxLogFinalizer', () => {
         '.jsonl',
         '.jsonl',
       ]);
+
+      // assert that the temporary files have been moved, not copied
+      expect(fs.existsSync(temporaryFiles[1])).toBe(false);
+      expect(fs.existsSync(temporaryFiles[2])).toBe(false);
     });
   });