diff --git a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt index 6a38e93b7e..9a54ab1d15 100644 --- a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt +++ b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt @@ -13,9 +13,11 @@ object LogConfig { private const val DEFAULT_FILE_LOG_PATTERN = "%d{HH:mm:ss.SSS} [%5level] %logger.%method: %msg%n" private const val DEFAULT_CONSOLE_LOG_PATTERN = "%highlight([%5level]) %msg%n" + private const val DEFAULT_LOG_LEVEL = "ALL" private val FILE_LOG_PATTERN: String = System.getenv("MAESTRO_CLI_LOG_PATTERN_FILE") ?: DEFAULT_FILE_LOG_PATTERN private val CONSOLE_LOG_PATTERN: String = System.getenv("MAESTRO_CLI_LOG_PATTERN_CONSOLE") ?: DEFAULT_CONSOLE_LOG_PATTERN + private val LOG_LEVEL: String = System.getenv("MAESTRO_CLI_LOG_LEVEL") ?: DEFAULT_LOG_LEVEL fun configure(logFileName: String, printToConsole: Boolean) { val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext @@ -27,7 +29,7 @@ object LogConfig { createAndAddConsoleAppender(loggerContext) } - loggerContext.getLogger("ROOT").level = Level.ALL + loggerContext.getLogger("ROOT").level = Level.toLevel(LOG_LEVEL, Level.ALL) } private fun createAndAddConsoleAppender(loggerContext: LoggerContext) { diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt index 36562697af..44fbe1d4da 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt @@ -8,7 +8,7 @@ import maestro.orchestra.MaestroCommand object Env { fun String.evaluateScripts(jsEngine: JsEngine): String { - val result = "(? val script = match.groups[1]?.value ?: "" @@ -20,7 +20,7 @@ object Env { } return result - .replace("\\\\\\\$\\{([^\$]*)}".toRegex()) { match -> + .replace("\\\\\\\$\\{(.*?)}".toRegex()) { match -> match.value.substringAfter('\\') } } diff --git a/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt b/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt index 80b4fee6da..27dd79dfb1 100644 --- a/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt +++ b/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt @@ -3,10 +3,12 @@ package maestro.orchestra.util import com.google.common.truth.Truth.assertThat import java.io.File import kotlin.random.Random +import maestro.js.GraalJsEngine import maestro.orchestra.ApplyConfigurationCommand import maestro.orchestra.DefineVariablesCommand import maestro.orchestra.MaestroCommand import maestro.orchestra.MaestroConfig +import maestro.orchestra.util.Env.evaluateScripts import maestro.orchestra.util.Env.withDefaultEnvVars import maestro.orchestra.util.Env.withEnv import maestro.orchestra.util.Env.withInjectedShellEnvVars @@ -60,4 +62,20 @@ class EnvTest { assertThat(withEnv).containsExactly(defineVariables, applyConfig) } + + @Test + fun `evaluateScripts regex`() { + val engine = GraalJsEngine() + val inputs = listOf( + "${'$'}{console.log('Hello!')}", + "${'$'}{console.log('Hello Money! $')}", + "${'$'}{console.log('$')}", + ) + + val evaluated = inputs.map { it.evaluateScripts(engine) } + + // "undefined" is the expected output when evaluating console.log successfully + assertThat(evaluated).containsExactly("undefined", "undefined", "undefined") + } + } diff --git a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt index 33b68efaae..3bb5e0e48c 100644 --- a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt +++ b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt @@ -48,6 +48,7 @@ import okio.buffer import okio.sink import java.io.File import java.lang.Long.max +import org.slf4j.LoggerFactory // TODO(bartkepacia): Use this in onCommandGeneratedOutput. // Caveat: @@ -169,6 +170,7 @@ class Orchestra( command, metadata.copy(logMessages = metadata.logMessages + msg) ) + jsLogger.info(msg) } val evaluatedCommand = command.evaluateScripts(jsEngine) @@ -1204,5 +1206,7 @@ class Orchestra( val REGEX_OPTIONS = setOf(RegexOption.IGNORE_CASE, RegexOption.DOT_MATCHES_ALL, RegexOption.MULTILINE) private const val MAX_ERASE_CHARACTERS = 50 + + private val jsLogger = LoggerFactory.getLogger("maestro.js.JsEngine.console.log") } }