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,37 @@ 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+ cypress_version = semver . coerce ( cypress_version ) . version ;
128+ // validate cypress.json only in case of cypress<10
129+ if (
130+ semverCompare ( cypress_version , "10.0.0" ) == - 1 &&
131+ lt_config [ "run_settings" ] [ "cypress_config_file" ] &&
132+ lt_config [ "run_settings" ] [ "cypress_config_file" ] != ""
133+ ) {
134+ if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
135+ reject ( "Error!! Cypress Config File does not exist" ) ;
136+ } else {
137+ let rawdata = fs . readFileSync (
138+ lt_config [ "run_settings" ] [ "cypress_config_file" ]
139+ ) ;
140+ try {
141+ let cypress_config = JSON . parse ( rawdata ) ;
142+ } catch {
143+ console . log (
144+ "Cypress.json is not parsed, please provide a valid json"
145+ ) ;
146+ reject ( "Error!! Cypress Config File does not has correct json" ) ;
147+ }
148+ }
149+ }
150+
151+
140152 if (
141153 lt_config [ "run_settings" ] [ "ignore_files" ] &&
142154 lt_config [ "run_settings" ] [ "ignore_files" ] . length > 0
@@ -208,14 +220,13 @@ module.exports = validate_config = function (lt_config, validation_configs) {
208220 reject ( "Smart UI porject name can not be blank" ) ;
209221 }
210222 }
211- //validate if reporter json file is passed and exists
212223 if (
213224 lt_config [ "run_settings" ] [ "reporter_config_file" ] &&
214225 lt_config [ "run_settings" ] [ "reporter_config_file" ] != ""
215226 ) {
216227 if ( ! fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
217228 reject (
218- "Error!! Reporter Json File does not exist, either remove the key reporter_config_file or pass a valid path"
229+ "Error!! Reporter Config File does not exist, Pass a valid path"
219230 ) ;
220231 } else {
221232 let rawdata = fs . readFileSync (
@@ -227,14 +238,20 @@ module.exports = validate_config = function (lt_config, validation_configs) {
227238 reject (
228239 "Error!! Reporter JSON File has no keys, either remove Key reporter_config_file from lambdatest config or pass some options"
229240 ) ;
241+ } else if ( reporter_config . reporterEnabled && reporter_config . reporterEnabled != "" ) {
242+ if ( ! reporter_config . reporterEnabled . includes ( "mochawesome" ) ) {
243+ console . log ( "Warning!! mochawesome reporter config not present. Command log may not be visible on dashboard" ) ;
244+ }
230245 }
231246 } catch {
232247 console . log (
233- "reporter_config_file is not parsed, please provide a valid json in Reporter Config"
248+ "reporter_config_file could not be parsed, please provide a valid json in Reporter Config"
234249 ) ;
235- reject ( "Error!! Reporter JSON File does not has correct json" ) ;
250+ reject ( "Error!! Reporter JSON File does not have correct json" ) ;
236251 }
237252 }
253+ } else {
254+ console . log ( "Warning !! Value of reporter_config_file parameter missing. Proceeding with default reporter config" )
238255 }
239256
240257 if (
@@ -336,6 +353,6 @@ module.exports = validate_config = function (lt_config, validation_configs) {
336353 } )
337354
338355 }
339- resolve ( "Validated the Config" ) ;
356+ resolve ( cypress_version ) ;
340357 } ) ;
341358} ;
0 commit comments