Skip to content

Commit e1407ec

Browse files
Merge pull request #120 from LambdaTest/dev
2.4.1
2 parents 4f569fb + e1e6f20 commit e1407ec

File tree

6 files changed

+154
-145
lines changed

6 files changed

+154
-145
lines changed

commands/build_info.js

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,75 @@
1-
const request = require("request")
2-
const constants = require("./utils/constants.js")
3-
const process = require("process")
4-
1+
const request = require("request");
2+
const constants = require("./utils/constants.js");
3+
const process = require("process");
54

65
function get_build_info(args) {
6+
return new Promise(function (resolve, reject) {
7+
var username = "";
8+
var access_key = "";
9+
//Check for username
10+
if ("user" in args) {
11+
username = args.user;
12+
} else if (process.env.LT_USERNAME) {
13+
console.log("Setting Username from ENV", process.env.LT_USERNAME);
14+
username = process.env.LT_USERNAME;
15+
} else {
16+
reject("Username not provided");
17+
}
718

8-
return new Promise(function (resolve, reject) {
9-
var username = ""
10-
var access_key = ""
11-
//Check for username
12-
if ("user" in args) {
13-
username = args.user
14-
} else if (process.env.LT_USERNAME) {
15-
console.log("Setting Username from ENV", process.env.LT_USERNAME)
16-
username = process.env.LT_USERNAME
17-
} else {
18-
reject("Username not provided")
19-
}
19+
//Check for access key
20+
if ("access_key" in args) {
21+
access_key = args.access_key;
22+
} else if (process.env.LT_ACCESS_KEY) {
23+
console.log("Setting Access Key from ENV", process.env.LT_ACCESS_KEY);
24+
access_key = process.env.LT_ACCESS_KEY;
25+
} else {
26+
reject("Access Key not provided");
27+
}
2028

21-
//Check for access key
22-
if ("access_key" in args) {
23-
access_key = args.access_key
24-
} else if (process.env.LT_ACCESS_KEY) {
25-
console.log("Setting Access Key from ENV", process.env.LT_ACCESS_KEY)
26-
access_key = process.env.LT_ACCESS_KEY
27-
} else {
28-
reject("Access Key not provided")
29-
}
29+
if (!("buildId" in args)) {
30+
reject("Please provide a build ID");
31+
}
32+
var env = "prod";
33+
if ("env" in args) {
34+
if (constants.ENVS.includes(args["env"])) {
35+
env = args["env"];
36+
} else {
37+
console.log(
38+
"Environment can be stage, beta or prod, setting Env to prod"
39+
);
40+
}
41+
}
3042

31-
if (!("buildId" in args)) {
32-
reject("Please provide a build ID")
43+
request(
44+
constants[env].BUILD_BASE_URL + args.buildId,
45+
{
46+
auth: {
47+
username: username,
48+
password: access_key,
49+
},
50+
},
51+
(err, res, body) => {
52+
if (err) {
53+
reject(err);
3354
}
34-
var env = "prod"
35-
if ("env" in args) {
36-
37-
if (["stage", "prod", "beta"].includes(args["env"])) {
38-
env = args["env"]
39-
40-
} else {
41-
console.log("Environment can be stage, beta or prod, setting Env to prod")
42-
43-
}
44-
55+
if (res.statusCode == "401") {
56+
resolve("Unauthorized");
57+
} else if (JSON.parse(body).status == "success") {
58+
resolve(JSON.parse(body).data);
59+
} else {
60+
resolve(JSON.parse(body).message);
4561
}
46-
47-
request(constants[env].BUILD_BASE_URL + args.buildId, {
48-
auth: {
49-
username: username,
50-
password: access_key
51-
}
52-
}, (err, res, body) => {
53-
if (err) {
54-
reject(err)
55-
}
56-
if (res.statusCode == "401") {
57-
resolve("Unauthorized")
58-
} else if (JSON.parse(body).status == "success") {
59-
resolve(JSON.parse(body).data)
60-
} else {
61-
resolve(JSON.parse(body).message)
62-
}
63-
});
64-
})
62+
}
63+
);
64+
});
6565
}
6666

6767
module.exports = function (args) {
68-
get_build_info(args).then(function (resp) {
69-
console.log(resp)
70-
}
71-
).catch(function (err) {
72-
console.log(err)
68+
get_build_info(args)
69+
.then(function (resp) {
70+
console.log(resp);
7371
})
74-
75-
72+
.catch(function (err) {
73+
console.log(err);
74+
});
7675
};

commands/build_stop.js

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,87 @@
1-
const request = require("request")
2-
const constants = require("./utils/constants.js")
3-
const process = require("process")
4-
1+
const request = require("request");
2+
const constants = require("./utils/constants.js");
3+
const process = require("process");
54

65
function stop_build(args) {
6+
return new Promise(function (resolve, reject) {
7+
var username = "";
8+
var access_key = "";
9+
//Check for username
10+
if ("user" in args) {
11+
username = args.user;
12+
} else if (process.env.LT_USERNAME) {
13+
console.log("Setting Username from ENV", process.env.LT_USERNAME);
14+
username = process.env.LT_USERNAME;
15+
} else {
16+
reject("Username not provided");
17+
}
718

8-
return new Promise(function (resolve, reject) {
9-
var username = ""
10-
var access_key = ""
11-
//Check for username
12-
if ("user" in args) {
13-
username = args.user
14-
} else if (process.env.LT_USERNAME) {
15-
console.log("Setting Username from ENV", process.env.LT_USERNAME)
16-
username = process.env.LT_USERNAME
17-
} else {
18-
reject("Username not provided")
19-
}
20-
21-
//Check for access key
22-
if ("access_key" in args) {
23-
access_key = args.access_key
24-
} else if (process.env.LT_ACCESS_KEY) {
25-
console.log("Setting Access Key from ENV", process.env.LT_ACCESS_KEY)
26-
access_key = process.env.LT_ACCESS_KEY
27-
} else {
28-
reject("Access Key not provided")
29-
}
30-
31-
if ((!("buildId" in args)) || args["buildid"] == "" || args["buildid"] == undefined) {
32-
reject("Please provide a build ID")
33-
}
34-
var env = "prod"
35-
if ("env" in args) {
36-
37-
if (["stage", "prod", "beta"].includes(args["env"])) {
38-
env = args["env"]
39-
40-
} else {
41-
console.log("Environment can be stage, beta or prod, setting Env to prod")
19+
//Check for access key
20+
if ("access_key" in args) {
21+
access_key = args.access_key;
22+
} else if (process.env.LT_ACCESS_KEY) {
23+
console.log("Setting Access Key from ENV", process.env.LT_ACCESS_KEY);
24+
access_key = process.env.LT_ACCESS_KEY;
25+
} else {
26+
reject("Access Key not provided");
27+
}
4228

43-
}
29+
if (
30+
!("buildId" in args) ||
31+
args["buildid"] == "" ||
32+
args["buildid"] == undefined
33+
) {
34+
reject("Please provide a build ID");
35+
}
36+
var env = "prod";
37+
if ("env" in args) {
38+
if (constants.ENVS.includes(args["env"])) {
39+
env = args["env"];
40+
} else {
41+
console.log(
42+
"Environment can be stage, beta or prod, setting Env to prod"
43+
);
44+
}
45+
}
4446

47+
let options = {
48+
url: constants[env].BUILD_STOP_URL + args.buildId,
49+
headers: {
50+
Authorization: "Token " + access_key,
51+
Username: username,
52+
},
53+
};
54+
request.put(options, function (err, resp, body) {
55+
if (err) {
56+
reject(err);
57+
} else {
58+
try {
59+
responseData = JSON.parse(body);
60+
} catch (e) {
61+
console.log("Error in JSON response", body);
62+
responseData = null;
4563
}
46-
47-
48-
let options = {
49-
url: constants[env].BUILD_STOP_URL + args.buildId,
50-
headers: {
51-
'Authorization': 'Token ' + access_key,
52-
'Username': username
53-
}
64+
if (resp.statusCode != 200) {
65+
if (responseData && responseData["error"]) {
66+
reject(responseData["error"]);
67+
} else {
68+
console.log(responseData);
69+
reject("error", responseData);
70+
}
71+
} else {
72+
resolve("Build Stopped successfully");
5473
}
55-
request.put(options, function (err, resp, body) {
56-
if (err) {
57-
reject(err);
58-
} else {
59-
try {
60-
responseData = JSON.parse(body);
61-
} catch (e) {
62-
console.log("Error in JSON response", body)
63-
responseData = null
64-
}
65-
if (resp.statusCode != 200) {
66-
if (responseData && responseData["error"]) {
67-
reject(responseData["error"]);
68-
} else {
69-
console.log(responseData)
70-
reject("error", responseData);
71-
}
72-
} else {
73-
resolve("Build Stopped successfully");
74-
}
75-
}
76-
});
77-
})
74+
}
75+
});
76+
});
7877
}
7978

8079
module.exports = function (args) {
81-
stop_build(args).then(function (resp) {
82-
console.log(resp)
83-
}
84-
).catch(function (err) {
85-
console.log(err)
80+
stop_build(args)
81+
.then(function (resp) {
82+
console.log(resp);
8683
})
87-
88-
84+
.catch(function (err) {
85+
console.log(err);
86+
});
8987
};

commands/generate_reports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function generate_report(args) {
9999
//set working enviornment
100100
var env = "prod";
101101
if ("env" in args) {
102-
if (["stage", "prod", "beta"].includes(args["env"])) {
102+
if (constants.ENVS.includes(args["env"])) {
103103
env = args["env"];
104104
} else {
105105
console.log(

commands/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ module.exports = function (args) {
2020
}
2121
var env = "prod";
2222
if ("env" in args) {
23-
if (["stage", "prod", "beta"].includes(args["env"])) {
23+
if (constants.ENVS.includes(args["env"])) {
2424
env = args["env"];
2525
} else {
2626
console.log(
27-
"Environment can be stage, beta or prod, setting Env to prod"
27+
"Environment can be stage, beta, preprod or prod, setting Env to prod"
2828
);
2929
}
3030
}

commands/utils/constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
SUPPORTED_CYPRESS_VERSIONS: ["5", "6"],
1212
BUILD_END_STATES: "&status=running,queued,created,initiated,pqueued",
1313
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
14+
ENVS: ["stage", "beta", "prod", "preprod"],
1415
prod: {
1516
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
1617
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
@@ -42,4 +43,15 @@ module.exports = {
4243
REPORT_URL:
4344
"https://stage-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
4445
},
46+
preprod: {
47+
INTEGRATION_BASE_URL: "https://preprod-api.lambdatest.com/liis",
48+
BUILD_BASE_URL:
49+
"https://preprod-api.lambdatest.com/automation/api/v1/builds/",
50+
BUILD_STOP_URL:
51+
"https://preprod-api.lambdatest.com/api/v1/test/stop?buildId=",
52+
SESSION_URL:
53+
"https://preprod-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
54+
REPORT_URL:
55+
"https://preprod-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
56+
},
4557
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambdatest-cypress-cli",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"description": "The lambdatest-cypress-cli is LambdaTest's command-line interface (CLI) aimed to help you run your Cypress tests on LambdaTest platform.",
55
"homepage": "https://github.com/LambdaTest/lambdatest-cypress-cli",
66
"author": "LambdaTest <[email protected]>",

0 commit comments

Comments
 (0)