diff --git a/commands/utils/archive.js b/commands/utils/archive.js index 274c564..5e13f27 100644 --- a/commands/utils/archive.js +++ b/commands/utils/archive.js @@ -38,7 +38,8 @@ function archive_project(lt_config) { archive.on("error", function (err) { console.log("ERROR", err); - throw err; + reject(err); + //throw err; }); // pipe archive data to the file @@ -68,9 +69,65 @@ function archive_project(lt_config) { console.log("Ignoring files: ", ignore_files); archive.glob( "**/*", - { cwd: process.cwd(), ignore: ignore_files }, + { cwd: process.cwd(), ignore: ignore_files, dot: true }, { prefix: "project/" } ); + //OverRide NPM Dependencies + if (lt_config.run_settings.npm_dependencies) { + console.log("Overriding NPM Dependencies"); + let rawdata = fs.readFileSync("package.json"); + + let package = JSON.parse(rawdata); + package.dependencies = lt_config.run_settings.npm_dependencies; + package.devDependencies = {}; + archive.append( + JSON.stringify(package, null, 4), + { + name: "project/package.json", + cwd: process.cwd(), + ignore: ignore_files, + }, + { prefix: "project/" } + ); + } + if ( + lt_config.run_settings.dep_tokens && + lt_config.run_settings.dep_tokens.length > 0 + ) { + if (fs.existsSync(".npmrc")) { + let raw_data = fs.readFileSync(".npmrc", "utf8"); + let replace_map = {}; + for (let i = 0; i < lt_config.run_settings.dep_tokens.length; i++) { + if (process.env[lt_config.run_settings.dep_tokens[i]]) { + //Used for creating regular expression by escaping the $ and {} + replace_map[ + "\\$\\{" + lt_config.run_settings.dep_tokens[i] + "\\}" + ] = process.env[lt_config.run_settings.dep_tokens[i]]; + //User for String replacement + replace_map["${" + lt_config.run_settings.dep_tokens[i] + "}"] = + process.env[lt_config.run_settings.dep_tokens[i]]; + } else { + reject("Dep Tokens are not in environment"); + return; + } + } + var re = new RegExp(Object.keys(replace_map).join("|"), "gi"); + raw_data = raw_data.replace(re, function (matched) { + return replace_map[matched]; + }); + archive.append( + raw_data, + { + name: "project/.npmrc", + cwd: process.cwd(), + ignore: ignore_files, + }, + { prefix: "project/" } + ); + } else { + reject("Dep Tokens are passed but .npmrc does not exist"); + } + } archive.finalize(); }); diff --git a/commands/utils/batch/batch_runner.js b/commands/utils/batch/batch_runner.js index 07f9f0e..43e1824 100644 --- a/commands/utils/batch/batch_runner.js +++ b/commands/utils/batch/batch_runner.js @@ -52,6 +52,12 @@ function run_test(payload, env = "prod") { if (parseInt(build_id) == 0) { reject("Some Error occured on Lambdatest Server"); } else { + //Write session_id to a file + data = { build_id: build_id, session_id: session_id }; + fs.writeFileSync( + "lambdatest_run.json", + JSON.stringify(data, null, 3) + ); console.log( `Uploaded tests successfully `, responseData["value"]["message"] diff --git a/commands/utils/default_config.js b/commands/utils/default_config.js index 3cd79d3..a19dd18 100644 --- a/commands/utils/default_config.js +++ b/commands/utils/default_config.js @@ -25,6 +25,9 @@ module.exports = { network: false, headless: false, reporter_config_file: "", + npm_dependencies: { + cypress: "9.0.0", + }, }, tunnel_settings: { tunnel: false, diff --git a/commands/utils/validate.js b/commands/utils/validate.js index 92b1cb6..c5f46b4 100644 --- a/commands/utils/validate.js +++ b/commands/utils/validate.js @@ -78,6 +78,11 @@ module.exports = validate_config = function (lt_config) { let rawdata = fs.readFileSync("package.json"); try { let package = JSON.parse(rawdata); + //Override npm_dependencies + if (lt_config.run_settings.npm_dependencies) { + package.dependencies = lt_config.run_settings.npm_dependencies; + package.devDependencies = {}; + } let cypress_flag = false; if (package.hasOwnProperty("dependencies")) { for (const [key, value] of Object.entries(package["dependencies"])) { diff --git a/package.json b/package.json index baa7c8f..cddc7f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lambdatest-cypress-cli", - "version": "2.1.7", + "version": "2.1.8", "description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.", "homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli", "author": "LambdaTest ",