11const fs = require ( "fs" ) ;
2+ const semver = require ( "semver" ) ;
3+ const semverCompare = require ( 'semver/functions/compare' ) ;
4+
25const constants = require ( "./constants.js" ) ;
36module . exports = validate_config = function ( lt_config , validation_configs ) {
47 console . log ( "validating config" ) ;
@@ -48,29 +51,9 @@ module.exports = validate_config = function (lt_config, validation_configs) {
4851 reject ( "Error!! Parallels value not correct" ) ;
4952 }
5053
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+
7355 //Validate if package.json is having the cypress dependency
56+ var cypress_version ;
7457 if ( ! fs . existsSync ( "package.json" ) ) {
7558 reject (
7659 "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) {
8972 for ( const [ key , value ] of Object . entries ( package [ "dependencies" ] ) ) {
9073 if ( key == "cypress" ) {
9174 cypress_flag = true ;
75+ cypress_version = value ;
9276 break ;
9377 }
9478 }
@@ -103,6 +87,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
10387 console . log ( key , value ) ;
10488 if ( key == "cypress" ) {
10589 cypress_flag = true ;
90+ cypress_version = value ;
10691 break ;
10792 }
10893 }
@@ -112,6 +97,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
11297 lt_config . run_settings . cypress_version != ""
11398 ) {
11499 cypress_flag = true ;
100+ cypress_version = lt_config . run_settings . cypress_version ;
115101 } else if (
116102 lt_config . run_settings . hasOwnProperty ( "cypress_version" ) &&
117103 lt_config . run_settings . cypress_version == ""
@@ -133,10 +119,38 @@ module.exports = validate_config = function (lt_config, validation_configs) {
133119 "Package.json is not parsed, please provide a valid json" ,
134120 e
135121 ) ;
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+ }
137150 }
138151 }
139152
153+
140154 if (
141155 lt_config [ "run_settings" ] [ "ignore_files" ] &&
142156 lt_config [ "run_settings" ] [ "ignore_files" ] . length > 0
@@ -209,13 +223,20 @@ module.exports = validate_config = function (lt_config, validation_configs) {
209223 }
210224 }
211225 //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"]);
212233 if (
213234 lt_config [ "run_settings" ] [ "reporter_config_file" ] &&
214235 lt_config [ "run_settings" ] [ "reporter_config_file" ] != ""
215236 ) {
216237 if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
217238 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"
219240 ) ;
220241 } else {
221242 let rawdata = fs . readFileSync (
@@ -227,14 +248,21 @@ module.exports = validate_config = function (lt_config, validation_configs) {
227248 reject (
228249 "Error!! Reporter JSON File has no keys, either remove Key reporter_config_file from lambdatest config or pass some options"
229250 ) ;
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+ }
230256 }
231257 } catch {
232258 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"
234260 ) ;
235- reject ( "Error!! Reporter JSON File does not has correct json" ) ;
261+ reject ( "Error!! Reporter JSON File does not have correct json" ) ;
236262 }
237263 }
264+ } else {
265+ console . log ( "Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config" )
238266 }
239267
240268 if (
@@ -336,6 +364,6 @@ module.exports = validate_config = function (lt_config, validation_configs) {
336364 } )
337365
338366 }
339- resolve ( "Validated the Config" ) ;
367+ resolve ( cypress_version ) ;
340368 } ) ;
341369} ;
0 commit comments