From 0e0494e51b7d0733ce49f749b49eb8fbea9b9f69 Mon Sep 17 00:00:00 2001
From: Rutvik Chandla <rutvik.c@browserstack.com>
Date: Wed, 18 Sep 2024 12:05:30 +0530
Subject: [PATCH 1/4] Keep CLI args as priority

---
 bin/helpers/utils.js | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js
index fc5fd614..347ee5c3 100644
--- a/bin/helpers/utils.js
+++ b/bin/helpers/utils.js
@@ -1365,10 +1365,12 @@ exports.setVideoCliConfig = (bsConfig, videoConfig) => {
   let user_cypress_version = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypress_version) ? bsConfig.run_settings.cypress_version.toString() : undefined;
   let cypress_major_version = (user_cypress_version && user_cypress_version.match(/^(\d+)/)) ? user_cypress_version.split(".")[0] : undefined;
   let config_args = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.config) ? bsConfig.run_settings.config : undefined;
-  if(this.isUndefined(user_cypress_version) || this.isUndefined(cypress_major_version) || parseInt(cypress_major_version) >= 13 ) {
-    let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
-    config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
-    logger.debug(`Setting default video true for cypress 13 and above in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
+  if(config_args && !config_args.includes('video')) {
+    if(this.isUndefined(user_cypress_version) || this.isUndefined(cypress_major_version) || parseInt(cypress_major_version) >= 13 ) {
+      let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
+      config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
+      logger.debug(`Setting default video true for cypress 13 and above in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
+    }
   }
   if (bsConfig.run_settings && this.isNotUndefined(config_args)) bsConfig["run_settings"]["config"] = config_args;
 }

From b7a1ba117b2d53163c38fe265d7042824d75e24f Mon Sep 17 00:00:00 2001
From: Rutvik Chandla <rutvik.c@browserstack.com>
Date: Wed, 18 Sep 2024 12:06:25 +0530
Subject: [PATCH 2/4] Bump cli version

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index de5757a1..be2b58eb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "browserstack-cypress-cli",
-  "version": "1.31.7",
+  "version": "1.31.8",
   "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
   "main": "index.js",
   "scripts": {

From 80b029387f020c36efcecad3e658f116bb36a684 Mon Sep 17 00:00:00 2001
From: Rutvik Chandla <rutvik.c@browserstack.com>
Date: Mon, 7 Oct 2024 11:51:37 +0530
Subject: [PATCH 3/4] fix video_config

---
 bin/helpers/utils.js | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js
index 347ee5c3..390117ac 100644
--- a/bin/helpers/utils.js
+++ b/bin/helpers/utils.js
@@ -1365,12 +1365,26 @@ exports.setVideoCliConfig = (bsConfig, videoConfig) => {
   let user_cypress_version = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypress_version) ? bsConfig.run_settings.cypress_version.toString() : undefined;
   let cypress_major_version = (user_cypress_version && user_cypress_version.match(/^(\d+)/)) ? user_cypress_version.split(".")[0] : undefined;
   let config_args = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.config) ? bsConfig.run_settings.config : undefined;
-  if(config_args && !config_args.includes('video')) {
-    if(this.isUndefined(user_cypress_version) || this.isUndefined(cypress_major_version) || parseInt(cypress_major_version) >= 13 ) {
-      let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
-      config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
-      logger.debug(`Setting default video true for cypress 13 and above in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
+  if(this.isUndefined(user_cypress_version) || this.isUndefined(cypress_major_version) || parseInt(cypress_major_version) >= 13 ) {
+    let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
+    config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
+    let params = config_args.split(",");
+    const finalParamsHash = {};
+
+    for (let i = 0; i < params.length; i++) {
+      const param = params[i].split('=');
+      if (finalParamsHash[param[0]] == undefined) {
+        finalParamsHash[param[0]] = param[1];
+      }
+    };
+
+    const arr = [];
+    for (const [key, value] of Object.entries(finalParamsHash)) {
+      arr.push(`${key}=${value}`);
     }
+    config_args = arr.join(",");
+    videoConfig["video"] = finalParamsHash["video"];
+    logger.debug(`Setting default video true for cypress 13 and above in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
   }
   if (bsConfig.run_settings && this.isNotUndefined(config_args)) bsConfig["run_settings"]["config"] = config_args;
 }

From d87431944e7eed37775282a4c6760abb335ed1ab Mon Sep 17 00:00:00 2001
From: Rutvik Chandla <97675949+RutvikChandla@users.noreply.github.com>
Date: Mon, 7 Oct 2024 11:52:35 +0530
Subject: [PATCH 4/4] Update package.json

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index be2b58eb..de5757a1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "browserstack-cypress-cli",
-  "version": "1.31.8",
+  "version": "1.31.7",
   "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
   "main": "index.js",
   "scripts": {