Skip to content

Commit a11ee89

Browse files
Japneet Singh ChawlaJapneet Singh Chawla
authored andcommitted
lambda run file added and npmrc support
1 parent fc3a312 commit a11ee89

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

commands/utils/archive.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function archive_project(lt_config) {
3838

3939
archive.on("error", function (err) {
4040
console.log("ERROR", err);
41-
throw err;
41+
reject(err);
42+
//throw err;
4243
});
4344

4445
// pipe archive data to the file
@@ -68,9 +69,52 @@ function archive_project(lt_config) {
6869
console.log("Ignoring files: ", ignore_files);
6970
archive.glob(
7071
"**/*",
71-
{ cwd: process.cwd(), ignore: ignore_files },
72+
{ cwd: process.cwd(), ignore: ignore_files, dot: true },
7273
{ prefix: "project/" }
7374
);
75+
if (
76+
lt_config["run_settings"]["dep_tokens"] &&
77+
lt_config["run_settings"]["dep_tokens"].length > 0
78+
) {
79+
if (fs.existsSync(".npmrc")) {
80+
let raw_data = fs.readFileSync(".npmrc", "utf8");
81+
let replace_map = {};
82+
for (
83+
let i = 0;
84+
i < lt_config["run_settings"]["dep_tokens"].length;
85+
i++
86+
) {
87+
if (process.env[lt_config["run_settings"]["dep_tokens"][i]]) {
88+
//Used for creating regular expression by escaping the $ and {}
89+
replace_map[
90+
"\\$\\{" + lt_config["run_settings"]["dep_tokens"][i] + "\\}"
91+
] = process.env[lt_config["run_settings"]["dep_tokens"][i]];
92+
//User for String replacement
93+
replace_map[
94+
"${" + lt_config["run_settings"]["dep_tokens"][i] + "}"
95+
] = process.env[lt_config["run_settings"]["dep_tokens"][i]];
96+
} else {
97+
reject("Dep Tokens are not in environment");
98+
return;
99+
}
100+
}
101+
var re = new RegExp(Object.keys(replace_map).join("|"), "gi");
102+
raw_data = raw_data.replace(re, function (matched) {
103+
return replace_map[matched];
104+
});
105+
archive.append(
106+
raw_data,
107+
{
108+
name: "project/.npmrc",
109+
cwd: process.cwd(),
110+
ignore: ignore_files,
111+
},
112+
{ prefix: "project/" }
113+
);
114+
} else {
115+
reject("Dep Tokens are passed but .npmrc does not exist");
116+
}
117+
}
74118

75119
archive.finalize();
76120
});

commands/utils/batch/batch_runner.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ function run_test(payload, env = "prod") {
5252
if (parseInt(build_id) == 0) {
5353
reject("Some Error occured on Lambdatest Server");
5454
} else {
55+
//Write session_id to a file
56+
data = { build_id: build_id, session_id: session_id };
57+
fs.writeFileSync(
58+
"lambdatest_run.json",
59+
JSON.stringify(data, null, 3)
60+
);
5561
console.log(
5662
`Uploaded tests successfully `,
5763
responseData["value"]["message"]

0 commit comments

Comments
 (0)