Skip to content

Commit

Permalink
Merge pull request wix#1937 from wix/proguard-friendly-invoke-handler
Browse files Browse the repository at this point in the history
Make invoke handler not-need proguard exclusion defs
  • Loading branch information
d4vidi authored Feb 27, 2020
2 parents f8c9434 + fcb8e7e commit 1d03751
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class ReactNativeReloadActionHandler(
}
}

class InvokeActionHandler @JvmOverloads constructor(
class InvokeActionHandler(
private val methodInvocation: MethodInvocation,
private val wsClient: WebSocketClient,
private val errorParser: (e: Throwable?) -> String = Log::getStackTraceString)
private val errorParse: (e: Throwable?) -> String)
: DetoxActionHandler {

override fun handle(params: String, messageId: Long) {
Expand All @@ -53,10 +53,10 @@ class InvokeActionHandler @JvmOverloads constructor(
wsClient.sendAction("invokeResult", mapOf<String, Any?>("result" to invocationResult), messageId)
} catch (e: InvocationTargetException) {
Log.e(LOG_TAG, "Exception", e)
wsClient.sendAction("error", mapOf<String, Any?>("error" to "${errorParser(e.targetException)}\nCheck device logs for full details!\n"), messageId)
wsClient.sendAction("error", mapOf<String, Any?>("error" to "${errorParse(e.targetException)}\nCheck device logs for full details!\n"), messageId)
} catch (e: Exception) {
Log.i(LOG_TAG, "Test exception", e)
wsClient.sendAction("testFailed", mapOf<String, Any?>("details" to "${errorParser(e)}\nCheck device logs for full details!\n"), messageId)
wsClient.sendAction("testFailed", mapOf<String, Any?>("details" to "${errorParse(e)}\nCheck device logs for full details!\n"), messageId)
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions detox/android/detox/src/main/java/com/wix/detox/DetoxManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import android.util.Log;

import com.github.anrwatchdog.ANRError;
import com.github.anrwatchdog.ANRWatchDog;
import com.wix.detox.instruments.DetoxInstrumentsManager;
import com.wix.detox.reactnative.ReactNativeExtension;
import com.wix.detox.systeminfo.Environment;
Expand All @@ -17,9 +14,11 @@
import java.util.HashMap;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.test.platform.app.InstrumentationRegistry;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;

/**
* Created by rotemm on 04/01/2017.
Expand All @@ -32,6 +31,13 @@ class DetoxManager implements WebSocketClient.ActionHandler {
private final static String DETOX_SESSION_ID_ARG_KEY = "detoxSessionId";
private final static String DETOX_RECORDING_PATH_ARG_KEY = "detoxInstrumRecPath";

private final static Function1<Throwable, String> errorParseFn = new Function1<Throwable, String>() {
@Override
public String invoke(Throwable t) {
return Log.getStackTraceString(t);
}
};

private String detoxServerUrl;
private String detoxSessionId;

Expand Down Expand Up @@ -150,8 +156,8 @@ private void initActionHandlers() {
actionHandlers.clear();
actionHandlers.put("isReady", readyActionHandler);
actionHandlers.put("reactNativeReload", new ReactNativeReloadActionHandler(reactNativeHostHolder, wsClient, testEngineFacade));
actionHandlers.put("invoke", new InvokeActionHandler(new MethodInvocation(), wsClient));
actionHandlers.put("currentStatus", new QueryStatusActionHandler(wsClient, testEngineFacade));
actionHandlers.put("invoke", new InvokeActionHandler(new MethodInvocation(), wsClient, errorParseFn));
actionHandlers.put("cleanup", new CleanupActionHandler(wsClient, testEngineFacade, new Function0<Unit>() {
@Override
public Unit invoke() {
Expand Down

0 comments on commit 1d03751

Please sign in to comment.