1
1
const fs = require ( "fs" ) ;
2
+ const semver = require ( "semver" ) ;
3
+ const semverCompare = require ( 'semver/functions/compare' ) ;
4
+
2
5
const constants = require ( "./constants.js" ) ;
3
6
module . exports = validate_config = function ( lt_config , validation_configs ) {
4
7
console . log ( "validating config" ) ;
@@ -48,29 +51,9 @@ module.exports = validate_config = function (lt_config, validation_configs) {
48
51
reject ( "Error!! Parallels value not correct" ) ;
49
52
}
50
53
51
- //validate if cypress config file is passed and exists
52
- if (
53
- lt_config [ "run_settings" ] [ "cypress_config_file" ] &&
54
- lt_config [ "run_settings" ] [ "cypress_config_file" ] != ""
55
- ) {
56
- if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
57
- reject ( "Error!! Cypress Config File does not exist" ) ;
58
- } else {
59
- let rawdata = fs . readFileSync (
60
- lt_config [ "run_settings" ] [ "cypress_config_file" ]
61
- ) ;
62
- try {
63
- let cypress_config = JSON . parse ( rawdata ) ;
64
- } catch {
65
- console . log (
66
- "Cypress.json is not parsed, please provide a valid json"
67
- ) ;
68
- reject ( "Error!! Cypress Config File does not has correct json" ) ;
69
- }
70
- }
71
- }
72
-
54
+
73
55
//Validate if package.json is having the cypress dependency
56
+ var cypress_version ;
74
57
if ( ! fs . existsSync ( "package.json" ) ) {
75
58
reject (
76
59
"Error!! Package.json file does not exist in the root on the project"
@@ -89,6 +72,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
89
72
for ( const [ key , value ] of Object . entries ( package [ "dependencies" ] ) ) {
90
73
if ( key == "cypress" ) {
91
74
cypress_flag = true ;
75
+ cypress_version = value ;
92
76
break ;
93
77
}
94
78
}
@@ -103,6 +87,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
103
87
console . log ( key , value ) ;
104
88
if ( key == "cypress" ) {
105
89
cypress_flag = true ;
90
+ cypress_version = value ;
106
91
break ;
107
92
}
108
93
}
@@ -112,6 +97,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
112
97
lt_config . run_settings . cypress_version != ""
113
98
) {
114
99
cypress_flag = true ;
100
+ cypress_version = lt_config . run_settings . cypress_version ;
115
101
} else if (
116
102
lt_config . run_settings . hasOwnProperty ( "cypress_version" ) &&
117
103
lt_config . run_settings . cypress_version == ""
@@ -133,10 +119,38 @@ module.exports = validate_config = function (lt_config, validation_configs) {
133
119
"Package.json is not parsed, please provide a valid json" ,
134
120
e
135
121
) ;
136
- reject ( "Error!! Package.json File does not has correct json" ) ;
122
+ reject ( "Error!! Package.json File does not have correct json" ) ;
123
+ }
124
+ }
125
+
126
+ //validate if cypress config file is passed and exists
127
+
128
+ // coerce cypress_version
129
+ cypress_version = semver . coerce ( cypress_version ) . version ;
130
+ // validate cypress.json only in case of cypress<10
131
+ if (
132
+ semverCompare ( cypress_version , "10.0.0" ) == - 1 &&
133
+ lt_config [ "run_settings" ] [ "cypress_config_file" ] &&
134
+ lt_config [ "run_settings" ] [ "cypress_config_file" ] != ""
135
+ ) {
136
+ if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
137
+ reject ( "Error!! Cypress Config File does not exist" ) ;
138
+ } else {
139
+ let rawdata = fs . readFileSync (
140
+ lt_config [ "run_settings" ] [ "cypress_config_file" ]
141
+ ) ;
142
+ try {
143
+ let cypress_config = JSON . parse ( rawdata ) ;
144
+ } catch {
145
+ console . log (
146
+ "Cypress.json is not parsed, please provide a valid json"
147
+ ) ;
148
+ reject ( "Error!! Cypress Config File does not has correct json" ) ;
149
+ }
137
150
}
138
151
}
139
152
153
+
140
154
if (
141
155
lt_config [ "run_settings" ] [ "ignore_files" ] &&
142
156
lt_config [ "run_settings" ] [ "ignore_files" ] . length > 0
@@ -209,13 +223,20 @@ module.exports = validate_config = function (lt_config, validation_configs) {
209
223
}
210
224
}
211
225
//validate if reporter json file is passed and exists
226
+ // if (
227
+ // lt_config["run_settings"]["reporter_config_file"] &&
228
+ // lt_config["run_settings"]["reporter_config_file"] == ""
229
+ // ){
230
+
231
+ // }
232
+ // console.log("config ", lt_config["run_settings"]["reporter_config_file"]);
212
233
if (
213
234
lt_config [ "run_settings" ] [ "reporter_config_file" ] &&
214
235
lt_config [ "run_settings" ] [ "reporter_config_file" ] != ""
215
236
) {
216
237
if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
217
238
reject (
218
- "Error!! Reporter Json File does not exist, either remove the key reporter_config_file or pass a valid path"
239
+ "Error!! Reporter Config File does not exist, Pass a valid path"
219
240
) ;
220
241
} else {
221
242
let rawdata = fs . readFileSync (
@@ -227,14 +248,21 @@ module.exports = validate_config = function (lt_config, validation_configs) {
227
248
reject (
228
249
"Error!! Reporter JSON File has no keys, either remove Key reporter_config_file from lambdatest config or pass some options"
229
250
) ;
251
+ } else if ( reporter_config . reporterEnabled && reporter_config . reporterEnabled != "" ) {
252
+ console . log ( "reporter_config.reporterEnabled " , reporter_config . reporterEnabled ) ;
253
+ if ( ! reporter_config . reporterEnabled . includes ( "mochawesome" ) ) {
254
+ reject ( "Error!! Please add mochawesome in reporterEnabled and add the related config" ) ;
255
+ }
230
256
}
231
257
} catch {
232
258
console . log (
233
- "reporter_config_file is not parsed, please provide a valid json in Reporter Config"
259
+ "reporter_config_file can not parsed, please provide a valid json in Reporter Config"
234
260
) ;
235
- reject ( "Error!! Reporter JSON File does not has correct json" ) ;
261
+ reject ( "Error!! Reporter JSON File does not have correct json" ) ;
236
262
}
237
263
}
264
+ } else {
265
+ console . log ( "Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config" )
238
266
}
239
267
240
268
if (
@@ -336,6 +364,6 @@ module.exports = validate_config = function (lt_config, validation_configs) {
336
364
} )
337
365
338
366
}
339
- resolve ( "Validated the Config" ) ;
367
+ resolve ( cypress_version ) ;
340
368
} ) ;
341
369
} ;
0 commit comments