From c5ce256093a214782849e153aa56ebcd5f15b2e0 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 13 Sep 2024 10:25:01 +0200 Subject: [PATCH] fix: Strip colors from server logs --- lib/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index da1b424e..caee8178 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -4,6 +4,7 @@ import {errors} from 'appium/driver'; export const ADB_SHELL_FEATURE = 'adb_shell'; export const BIDI_EVENT_NAME = 'bidiEvent'; export const GET_SERVER_LOGS_FEATURE = 'get_server_logs'; +const COLOR_CODE_PATTERN = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex /** * Assert the presence of particular keys in the given object @@ -64,9 +65,10 @@ export async function removeAllSessionWebSocketHandlers(server, sessionId) { * @returns {LogEntry} */ export function nativeLogEntryToSeleniumEntry (x) { + const msg = _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`; return toLogRecord( - _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`, - /** @type {any} */ (x).timestamp ?? Date.now() + /** @type {any} */ (x).timestamp ?? Date.now(), + _.replace(msg, COLOR_CODE_PATTERN, '') ); }