Skip to content

Commit 6090af7

Browse files
Merge pull request #193 from LambdaTest/dev
3.0.2
2 parents 9095327 + 32c18d2 commit 6090af7

File tree

4 files changed

+125
-86
lines changed

4 files changed

+125
-86
lines changed

commands/utils/archive.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function archive_project(lt_config) {
104104
lt_config.run_settings.cypress_version
105105
) {
106106
console.log("Overriding Cypress Version");
107-
if (package.dependencies.hasOwnProperty("cypress")) {
107+
if (
108+
package.hasOwnProperty("dependencies") &&
109+
package.dependencies.hasOwnProperty("cypress")
110+
) {
108111
package.dependencies.cypress = semver.coerce(
109112
lt_config.run_settings.cypress_version
110113
).version;
@@ -114,7 +117,10 @@ function archive_project(lt_config) {
114117
).version;
115118
}
116119
} else {
117-
if (package.dependencies.hasOwnProperty("cypress")) {
120+
if (
121+
package.hasOwnProperty("dependencies") &&
122+
package.dependencies.hasOwnProperty("cypress")
123+
) {
118124
package.dependencies.cypress = semver.coerce(
119125
package.dependencies.cypress
120126
).version;
@@ -233,7 +239,10 @@ function archive_batch(lt_config, batch) {
233239
} else if (!lt_config["run_settings"]["cypress_config_file"]) {
234240
archive.append("{}", { name: constants.CYPRESS_CONFIG_NAME });
235241
}
236-
if (lt_config["run_settings"]["reporter_config_file"] && lt_config["run_settings"]["reporter_config_file"] !="") {
242+
if (
243+
lt_config["run_settings"]["reporter_config_file"] &&
244+
lt_config["run_settings"]["reporter_config_file"] != ""
245+
) {
237246
if (fs.existsSync(lt_config["run_settings"]["reporter_config_file"])) {
238247
let rawdata = fs.readFileSync(
239248
lt_config["run_settings"]["reporter_config_file"]

commands/utils/batch/batcher.js

Lines changed: 93 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,112 @@
1-
const glob = require('glob')
2-
const fs = require('fs')
3-
const path = require('path')
1+
const glob = require("glob");
2+
const fs = require("fs");
3+
const path = require("path");
44

55
function slash(path) {
6-
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
7-
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
6+
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
7+
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
88

9-
if (isExtendedLengthPath || hasNonAscii) {
10-
return path;
11-
}
9+
if (isExtendedLengthPath || hasNonAscii) {
10+
return path;
11+
}
1212

13-
return path.replace(/\\/g, '/');
13+
return path.replace(/\\/g, "/");
1414
}
1515

1616
function get_required_sessions(browsers) {
17-
let combinations = []
18-
for (b in browsers) {
19-
for (v in browsers[b]["versions"]) {
20-
combinations.push({
21-
"browser": browsers[b]["browser"],
22-
"platform": browsers[b]["platform"],
23-
"version": browsers[b]["versions"][v]
24-
25-
})
26-
}
17+
let combinations = [];
18+
for (b in browsers) {
19+
for (v in browsers[b]["versions"]) {
20+
combinations.push({
21+
browser: browsers[b]["browser"],
22+
platform: browsers[b]["platform"],
23+
version: browsers[b]["versions"][v],
24+
});
2725
}
28-
return combinations
29-
26+
}
27+
return combinations;
3028
}
31-
function get_spec_files(files) {
32-
return new Promise(function (resolve, reject) {
33-
let matched_files = []
34-
for (i in files) {
35-
matched_files = matched_files.concat(glob.sync(files[i]))
36-
}
37-
if (matched_files.length == 0) {
38-
reject("Spec files are not present")
39-
}
40-
for (i in matched_files) {
41-
if (!fs.existsSync(matched_files[i])) {
42-
reject("Spec files are not present")
43-
}
29+
function get_spec_files(files, exclude_files) {
30+
return new Promise(function (resolve, reject) {
31+
let matched_files = [];
32+
let files_to_exclude = [];
33+
34+
for (i in files) {
35+
matched_files = matched_files.concat(glob.sync(files[i]));
36+
}
37+
for (i in exclude_files) {
38+
files_to_exclude = files_to_exclude.concat(glob.sync(exclude_files[i]));
39+
}
40+
let remaining_files = [];
41+
for (i in matched_files) {
42+
let deleted = false;
43+
for (let j = 0; j < files_to_exclude.length; j++) {
44+
if (matched_files[i] == files_to_exclude[j]) {
45+
deleted = true;
46+
break;
4447
}
45-
resolve(matched_files)
46-
})
48+
}
49+
if (deleted) {
50+
continue;
51+
} else {
52+
remaining_files.push(matched_files[i]);
53+
}
54+
if (!fs.existsSync(matched_files[i])) {
55+
reject("Spec files are not present");
56+
}
57+
}
58+
if (remaining_files.length == 0) {
59+
reject("Spec files are not present");
60+
}
61+
resolve(remaining_files);
62+
});
4763
}
4864

4965
function get_all_tests(lt_config) {
50-
return new Promise(function (resolve, reject) {
51-
let browsers = get_required_sessions(lt_config['browsers'])
52-
get_spec_files(lt_config["run_settings"]["specs"]).then(function (specs) {
53-
let tests = []
54-
for (let i in specs) {
55-
let relativePath = slash(path.relative(process.cwd(), specs[i]));
56-
for (let j in browsers) {
57-
tests.push({
58-
"spec_file": specs[i],
59-
"path": relativePath,
60-
"browser": browsers[j]["browser"],
61-
"platform": browsers[j]["platform"],
62-
"version": browsers[j]["version"]
63-
})
64-
}
65-
}
66-
resolve(tests)
67-
68-
}).catch(function (err) {
69-
reject(err)
70-
})
71-
})
72-
66+
return new Promise(function (resolve, reject) {
67+
let browsers = get_required_sessions(lt_config["browsers"]);
68+
get_spec_files(
69+
lt_config["run_settings"]["specs"],
70+
lt_config["run_settings"]["exclude_specs"]
71+
)
72+
.then(function (specs) {
73+
let tests = [];
74+
for (let i in specs) {
75+
let relativePath = slash(path.relative(process.cwd(), specs[i]));
76+
for (let j in browsers) {
77+
tests.push({
78+
spec_file: specs[i],
79+
path: relativePath,
80+
browser: browsers[j]["browser"],
81+
platform: browsers[j]["platform"],
82+
version: browsers[j]["version"],
83+
});
84+
}
85+
}
86+
resolve(tests);
87+
})
88+
.catch(function (err) {
89+
reject(err);
90+
});
91+
});
7392
}
7493

75-
7694
function make_batches(lt_config) {
77-
return new Promise(function (resolve, reject) {
78-
get_all_tests(lt_config).then(function (test_suite) {
79-
parallels = lt_config["run_settings"]["parallels"]
80-
resolve([test_suite])
81-
}).then(function (err) {
82-
console.log(err)
83-
}).catch(function (err) {
84-
console.log(err)
85-
})
86-
87-
})
95+
return new Promise(function (resolve, reject) {
96+
get_all_tests(lt_config)
97+
.then(function (test_suite) {
98+
parallels = lt_config["run_settings"]["parallels"];
99+
resolve([test_suite]);
100+
})
101+
.then(function (err) {
102+
console.log(err);
103+
})
104+
.catch(function (err) {
105+
console.log(err);
106+
});
107+
});
88108
}
89109

90-
91110
module.exports = {
92-
make_batches: make_batches
93-
}
111+
make_batches: make_batches,
112+
};

commands/utils/set_args.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,12 @@ function sync_args_from_cmd(args) {
224224

225225
// if reporter_config_file parameter, add it in lt config alongwith a warning on console
226226
if (!lt_config["run_settings"]["reporter_config_file"]) {
227-
console.log("Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config");
228-
lt_config["run_settings"]["reporter_config_file"] = constants.LT_BASE_REPORTER_CONFIG_FILE_NAME;
227+
console.log(
228+
"Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config"
229+
);
230+
lt_config["run_settings"]["reporter_config_file"] =
231+
constants.LT_BASE_REPORTER_CONFIG_FILE_NAME;
229232
}
230-
231233

232234
if ("cypress_version" in args) {
233235
lt_config["run_settings"]["cypress_version"] = args["cypress_version"];
@@ -341,13 +343,13 @@ function sync_args_from_cmd(args) {
341343
sys_env_vars = lt_config["run_settings"]["sys_envs"];
342344
}
343345

344-
if (sys_env_vars){
346+
if (sys_env_vars) {
345347
sys_env_vars = sys_env_vars.trim();
346348
sys_env_vars = sys_env_vars.split(";");
347-
349+
348350
for (index in sys_env_vars) {
349351
envItem = sys_env_vars[index];
350-
if (envItem){
352+
if (envItem) {
351353
envKeyValue = envItem.split("=");
352354
envKey = envKeyValue[0];
353355
envValue = envKeyValue[1];
@@ -356,8 +358,17 @@ function sync_args_from_cmd(args) {
356358
}
357359
}
358360
lt_config["run_settings"]["sys_envs"] = envs;
359-
360361

362+
if ("exclude_specs" in lt_config["run_settings"]) {
363+
lt_config["run_settings"]["exclude_specs"] =
364+
lt_config["run_settings"]["exclude_specs"].split(",");
365+
} else {
366+
lt_config["run_settings"]["exclude_specs"] == [];
367+
}
368+
console.log(
369+
"specs to exclude are ",
370+
lt_config["run_settings"]["exclude_specs"]
371+
);
361372
//get specs from current directory if specs are not passed in config or cli
362373
if (
363374
(lt_config["run_settings"]["specs"] == undefined ||

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lambdatest-cypress-cli",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
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]>",
@@ -37,4 +37,4 @@
3737
"engines": {
3838
"node": ">=0.6.0"
3939
}
40-
}
40+
}

0 commit comments

Comments
 (0)