Skip to content

Commit

Permalink
Merge pull request #97 from LambdaTest/dev
Browse files Browse the repository at this point in the history
Release 2.1.8
  • Loading branch information
japneetlambdatest authored Feb 4, 2022
2 parents fc3a312 + b570e38 commit 4012ae5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
61 changes: 59 additions & 2 deletions commands/utils/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
Expand Down
6 changes: 6 additions & 0 deletions commands/utils/batch/batch_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions commands/utils/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = {
network: false,
headless: false,
reporter_config_file: "",
npm_dependencies: {
cypress: "9.0.0",
},
},
tunnel_settings: {
tunnel: false,
Expand Down
5 changes: 5 additions & 0 deletions commands/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"])) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down

0 comments on commit 4012ae5

Please sign in to comment.