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
}
@@ -100,9 +84,9 @@ module.exports = validate_config = function (lt_config, validation_configs) {
100
84
for ( const [ key , value ] of Object . entries (
101
85
package [ "devDependencies" ]
102
86
) ) {
103
- console . log ( key , value ) ;
104
87
if ( key == "cypress" ) {
105
88
cypress_flag = true ;
89
+ cypress_version = value ;
106
90
break ;
107
91
}
108
92
}
@@ -112,6 +96,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
112
96
lt_config . run_settings . cypress_version != ""
113
97
) {
114
98
cypress_flag = true ;
99
+ cypress_version = lt_config . run_settings . cypress_version ;
115
100
} else if (
116
101
lt_config . run_settings . hasOwnProperty ( "cypress_version" ) &&
117
102
lt_config . run_settings . cypress_version == ""
@@ -133,10 +118,38 @@ module.exports = validate_config = function (lt_config, validation_configs) {
133
118
"Package.json is not parsed, please provide a valid json" ,
134
119
e
135
120
) ;
136
- reject ( "Error!! Package.json File does not has correct json" ) ;
121
+ reject ( "Error!! Package.json File does not have correct json" ) ;
137
122
}
138
123
}
139
124
125
+ //validate if cypress config file is passed and exists
126
+
127
+ // coerce cypress_version
128
+ cypress_version = semver . coerce ( cypress_version ) . version ;
129
+ // validate cypress.json only in case of cypress<10
130
+ if (
131
+ semverCompare ( cypress_version , "10.0.0" ) == - 1 &&
132
+ lt_config [ "run_settings" ] [ "cypress_config_file" ] &&
133
+ lt_config [ "run_settings" ] [ "cypress_config_file" ] != ""
134
+ ) {
135
+ if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
136
+ reject ( "Error!! Cypress Config File does not exist" ) ;
137
+ } else {
138
+ let rawdata = fs . readFileSync (
139
+ lt_config [ "run_settings" ] [ "cypress_config_file" ]
140
+ ) ;
141
+ try {
142
+ let cypress_config = JSON . parse ( rawdata ) ;
143
+ } catch {
144
+ console . log (
145
+ "Cypress.json is not parsed, please provide a valid json"
146
+ ) ;
147
+ reject ( "Error!! Cypress Config File does not has correct json" ) ;
148
+ }
149
+ }
150
+ }
151
+
152
+
140
153
if (
141
154
lt_config [ "run_settings" ] [ "ignore_files" ] &&
142
155
lt_config [ "run_settings" ] [ "ignore_files" ] . length > 0
@@ -208,14 +221,13 @@ module.exports = validate_config = function (lt_config, validation_configs) {
208
221
reject ( "Smart UI porject name can not be blank" ) ;
209
222
}
210
223
}
211
- //validate if reporter json file is passed and exists
212
224
if (
213
225
lt_config [ "run_settings" ] [ "reporter_config_file" ] &&
214
226
lt_config [ "run_settings" ] [ "reporter_config_file" ] != ""
215
227
) {
216
228
if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
217
229
reject (
218
- "Error!! Reporter Json File does not exist, either remove the key reporter_config_file or pass a valid path"
230
+ "Error!! Reporter Config File does not exist, Pass a valid path"
219
231
) ;
220
232
} else {
221
233
let rawdata = fs . readFileSync (
@@ -227,14 +239,21 @@ module.exports = validate_config = function (lt_config, validation_configs) {
227
239
reject (
228
240
"Error!! Reporter JSON File has no keys, either remove Key reporter_config_file from lambdatest config or pass some options"
229
241
) ;
242
+ } else if ( reporter_config . reporterEnabled && reporter_config . reporterEnabled != "" ) {
243
+ console . log ( "reporter_config.reporterEnabled " , reporter_config . reporterEnabled ) ;
244
+ if ( ! reporter_config . reporterEnabled . includes ( "mochawesome" ) ) {
245
+ reject ( "Error!! Please add mochawesome in reporterEnabled and add the related config" ) ;
246
+ }
230
247
}
231
248
} catch {
232
249
console . log (
233
- "reporter_config_file is not parsed, please provide a valid json in Reporter Config"
250
+ "reporter_config_file can not parsed, please provide a valid json in Reporter Config"
234
251
) ;
235
- reject ( "Error!! Reporter JSON File does not has correct json" ) ;
252
+ reject ( "Error!! Reporter JSON File does not have correct json" ) ;
236
253
}
237
254
}
255
+ } else {
256
+ console . log ( "Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config" )
238
257
}
239
258
240
259
if (
@@ -336,6 +355,6 @@ module.exports = validate_config = function (lt_config, validation_configs) {
336
355
} )
337
356
338
357
}
339
- resolve ( "Validated the Config" ) ;
358
+ resolve ( cypress_version ) ;
340
359
} ) ;
341
360
} ;
0 commit comments