Skip to content

Commit 1c3990e

Browse files
committed
prevent test error in case base reporter config file is deleted
1 parent 5ed78d0 commit 1c3990e

File tree

5 files changed

+102
-22
lines changed

5 files changed

+102
-22
lines changed

commands/init.js

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const { config } = require('yargs');
55
const constants = require('./utils/constants.js')
66

77
function create_file(file_path, content) {
8-
fs.writeFile(file_path, content, function (err) {
8+
// console.log("creating file at - ", file_path);
9+
// console.log("file content - ", content);
10+
fs.writeFileSync(file_path, content, function (err) {
911
if (err) throw err;
1012
console.log('Saved at ',file_path);
1113
});
12-
}
14+
};
1315

1416
function create_ltconfig_file(args) {
1517
let cv=9.6
@@ -47,13 +49,17 @@ function create_ltconfig_file(args) {
4749
}
4850
};
4951

50-
function create_base_reporter_config_file(args) {
51-
let config = require('./utils/default_reporter_config.js')
52-
let content = JSON.stringify(config, null, 3);
53-
if (args._.length == 1) {
54-
create_file(constants.LT_BASE_REPORTER_CONFIG_FILE_NAME, content)
55-
}
56-
};
52+
// function create_base_reporter_config_file(args) {
53+
// let config = require('./utils/default_reporter_config.js')
54+
// let content = JSON.stringify(config, null, 3);
55+
// console.log("len ", args._.length);
56+
// if (args._.length == 1) {
57+
// console.log("creating file");
58+
// create_file(constants.LT_BASE_REPORTER_CONFIG_FILE_NAME, content)
59+
// }else{
60+
// console.log("ELSE");
61+
// }
62+
// };
5763

5864
function create_custom_support_file(args){
5965
const pathToFile = path.join(__dirname, "default_custom_support_file.js");
@@ -68,12 +74,72 @@ function create_custom_support_file(args){
6874
});
6975
}
7076

71-
module.exports = function (args) {
72-
create_ltconfig_file(args);
77+
function create_base_reporter_config_file(args) {
78+
let config = require('./utils/default_reporter_config.js')
79+
let content = JSON.stringify(config, null, 3);
80+
81+
console.log("content - ", content);
82+
console.log("len ", args._.length);
83+
if (args._.length == 1) {
84+
console.log("creating file");
85+
create_file(constants.LT_BASE_REPORTER_CONFIG_FILE_NAME, content)
86+
}else{
87+
console.log("ELSE");
88+
}
89+
};
90+
91+
function init_implementation(args){
92+
console.log("args - ", args);
93+
// process.exit(1);
94+
// create_ltconfig_file(args);
7395
create_base_reporter_config_file(args);
7496
if ("cv" in args){
7597
if (parseInt(args["cv"])>=10){
7698
create_custom_support_file(args);
7799
}
78100
}
79101
};
102+
// module.exports = function (args) {
103+
module.exports = {
104+
create_base_reporter_config_file,init_implementation
105+
// this.create_base_reporter_config_file = function (args) {
106+
// let config = require('./utils/default_reporter_config.js')
107+
// let content = JSON.stringify(config, null, 3);
108+
// console.log("len ", args._.length);
109+
// if (args._.length == 1) {
110+
// console.log("creating file");
111+
// create_file(constants.LT_BASE_REPORTER_CONFIG_FILE_NAME, content)
112+
// }else{
113+
// console.log("ELSE");
114+
// }
115+
// };
116+
117+
118+
// create_base_reporter_config_file: create_base_reporter_config_file,
119+
// create_base_reporter_config_file: function (args) {
120+
// let config = require('./utils/default_reporter_config.js')
121+
// let content = JSON.stringify(config, null, 3);
122+
// console.log("len ", args._.length);
123+
// if (args._.length == 1) {
124+
// console.log("creating file");
125+
// create_file(constants.LT_BASE_REPORTER_CONFIG_FILE_NAME, content)
126+
// }else{
127+
// console.log("ELSE");
128+
// }
129+
// },
130+
131+
132+
133+
134+
135+
136+
// console.log("args - ", args);
137+
// // process.exit(1);
138+
// // create_ltconfig_file(args);
139+
// create_base_reporter_config_file(args);
140+
// if ("cv" in args){
141+
// if (parseInt(args["cv"])>=10){
142+
// create_custom_support_file(args);
143+
// }
144+
// }
145+
};

commands/utils/batch/batcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ function get_spec_files(files, exclude_files) {
5252
remaining_files.push(matched_files[i]);
5353
}
5454
if (!fs.existsSync(matched_files[i])) {
55-
reject("Spec files are not present");
55+
reject("Error! Spec files are not present");
5656
}
5757
}
5858
if (remaining_files.length == 0) {
59-
reject("Spec files are not present");
59+
reject("Error! Spec files are not present");
6060
}
6161
resolve(remaining_files);
6262
});

commands/utils/constants.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ module.exports = {
2727
"https://api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
2828
},
2929
beta: {
30-
INTEGRATION_BASE_URL:
31-
"https://api-cypress-v2-dev.lambdatestinternal.com/liis",
30+
INTEGRATION_BASE_URL: "https://api-envrn-dev.lambdatestinternal.com/liis",
3231
BUILD_BASE_URL:
33-
"https://api-cypress-v2-dev.lambdatestinternal.com/automation/api/v1/builds/",
32+
"https://api-envrn-dev.lambdatestinternal.com/automation/api/v1/builds/",
3433
BUILD_STOP_URL:
35-
"https://api-cypress-v2-dev.lambdatestinternal.com/api/v1/test/stop?sessionId=",
34+
"https://api-envrn-dev.lambdatestinternal.com/api/v1/test/stop?sessionId=",
3635
SESSION_URL:
37-
"https://api-cypress-v2-dev.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
36+
"https://api-envrn-dev.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
3837
REPORT_URL:
39-
"https://api-cypress-v2-dev.lambdatestinternal.com/automation/api/v1/cypress/artefacts/test/",
38+
"https://api-envrn-dev.lambdatestinternal.com/automation/api/v1/cypress/artefacts/test/",
4039
},
40+
4141
stage: {
4242
INTEGRATION_BASE_URL: "https://stage-api.lambdatestinternal.com/liis",
4343
BUILD_BASE_URL:

commands/utils/set_args.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const constants = require("./constants.js");
2+
var init_commands = require("./../init.js");
3+
24
const fs = require("fs");
35
const path = require("path");
46
const process = require("process");
@@ -237,6 +239,14 @@ function sync_args_from_cmd(args) {
237239
console.log(
238240
"Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config"
239241
);
242+
// make sure that the default file exists on user system. If not, place it. There is a possibility that
243+
// user may have delete it from his system.
244+
if (!fs.existsSync(lt_config["run_settings"]["reporter_config_file"])) {
245+
console.log("!! Warning, Creating the default reporter config file");
246+
init_commands.create_base_reporter_config_file(args);
247+
// process.exit(1);
248+
249+
}
240250
lt_config["run_settings"]["reporter_config_file"] =
241251
constants.LT_BASE_REPORTER_CONFIG_FILE_NAME;
242252
}

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env node
22

3-
const { init } = require("./commands/init");
3+
// const { init } = require("./commands/init");
4+
const { init_implementation } = require("./commands/init.js");
45

6+
console.log("init_implementation -> ", init_implementation);
57
const argv = require("yargs")
68
.usage("Usage: $0 <command> [options]")
79
.command(
810
"init",
9-
"create an intial config file",
11+
"create an initial config file",
1012
function (yargs) {
1113
return yargs
1214
.option("cv", {
@@ -21,7 +23,9 @@ const argv = require("yargs")
2123
});
2224
},
2325
function (argv) {
24-
require("./commands/init")(argv);
26+
// init.init_implementation(argv);
27+
init_implementation(argv);
28+
// require("./commands/init")(argv);
2529
}
2630
)
2731
.command(

0 commit comments

Comments
 (0)