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 }
@@ -100,9 +84,9 @@ module.exports = validate_config = function (lt_config, validation_configs) {
10084 for ( const [ key , value ] of Object . entries (
10185 package [ "devDependencies" ]
10286 ) ) {
103- console . log ( key , value ) ;
10487 if ( key == "cypress" ) {
10588 cypress_flag = true ;
89+ cypress_version = value ;
10690 break ;
10791 }
10892 }
@@ -112,6 +96,7 @@ module.exports = validate_config = function (lt_config, validation_configs) {
11296 lt_config . run_settings . cypress_version != ""
11397 ) {
11498 cypress_flag = true ;
99+ cypress_version = lt_config . run_settings . cypress_version ;
115100 } else if (
116101 lt_config . run_settings . hasOwnProperty ( "cypress_version" ) &&
117102 lt_config . run_settings . cypress_version == ""
@@ -133,10 +118,38 @@ module.exports = validate_config = function (lt_config, validation_configs) {
133118 "Package.json is not parsed, please provide a valid json" ,
134119 e
135120 ) ;
136- reject ( "Error!! Package.json File does not has correct json" ) ;
121+ reject ( "Error!! Package.json File does not have correct json" ) ;
137122 }
138123 }
139124
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+
140153 if (
141154 lt_config [ "run_settings" ] [ "ignore_files" ] &&
142155 lt_config [ "run_settings" ] [ "ignore_files" ] . length > 0
@@ -208,14 +221,13 @@ module.exports = validate_config = function (lt_config, validation_configs) {
208221 reject ( "Smart UI porject name can not be blank" ) ;
209222 }
210223 }
211- //validate if reporter json file is passed and exists
212224 if (
213225 lt_config [ "run_settings" ] [ "reporter_config_file" ] &&
214226 lt_config [ "run_settings" ] [ "reporter_config_file" ] != ""
215227 ) {
216228 if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
217229 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"
219231 ) ;
220232 } else {
221233 let rawdata = fs . readFileSync (
@@ -227,14 +239,21 @@ module.exports = validate_config = function (lt_config, validation_configs) {
227239 reject (
228240 "Error!! Reporter JSON File has no keys, either remove Key reporter_config_file from lambdatest config or pass some options"
229241 ) ;
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+ }
230247 }
231248 } catch {
232249 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"
234251 ) ;
235- reject ( "Error!! Reporter JSON File does not has correct json" ) ;
252+ reject ( "Error!! Reporter JSON File does not have correct json" ) ;
236253 }
237254 }
255+ } else {
256+ console . log ( "Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config" )
238257 }
239258
240259 if (
@@ -336,6 +355,6 @@ module.exports = validate_config = function (lt_config, validation_configs) {
336355 } )
337356
338357 }
339- resolve ( "Validated the Config" ) ;
358+ resolve ( cypress_version ) ;
340359 } ) ;
341360} ;
0 commit comments