@@ -15,6 +15,7 @@ const reports = require("../../../commands/generate_reports.js");
1515const { fail } = require ( "yargs" ) ;
1616const https = require ( 'https' ) ;
1717const axios = require ( 'axios' ) ;
18+ const converter = require ( "../../../converter/converter.js" ) ;
1819
1920var batchCounter = 0 ;
2021var totalBatches = 0 ;
@@ -99,146 +100,149 @@ async function run(lt_config, batches, env) {
99100 //console.log("Total number of batches " + totalBatches);
100101 return new Promise ( function ( resolve , reject ) {
101102 //archive the project i.e the current working directory
102- archive
103- . archive_project ( lt_config )
104- . then ( function ( file_obj ) {
105- project_file = file_obj [ "name" ] ;
106- lt_config [ "run_settings" ] [ "project_file" ] = project_file ;
107- //upload the project and get the project link
108- uploader
109- . upload_zip ( lt_config , file_obj [ "name" ] , "project" , env )
110- . then ( async function ( resp ) {
111- // TODO: remove hard check for undefined. handle it using nested promise rejection
112- if ( resp == undefined ) {
113- console . log (
114- "Either your creds are invalid or something is wrong with the configs provided"
115- ) ;
116- return ;
117- }
118- //add project link in lt config
119- project_url = resp [ "value" ] [ "message" ] . split ( "?" ) [ 0 ] . split ( "/" ) ;
120- project_url = project_url [ project_url . length - 1 ] ;
121- lt_config [ "run_settings" ] [ "project_url" ] = project_url ;
122- lt_config [ "test_suite" ] = batches [ 0 ] ;
123- archive
124- . archive_batch ( lt_config , batches [ 0 ] , env )
125- . then ( async function ( file_obj ) {
126- uploader
127- . upload_zip ( lt_config , file_obj [ "name" ] , "tests" , env )
128- . then ( async function ( resp ) {
129- var payload = JSON . stringify ( {
130- payload : {
131- test_file : resp [ "value" ] [ "message" ] . split ( "?" ) [ 0 ] ,
132- } ,
133- username : lt_config [ "lambdatest_auth" ] [ "username" ] ,
134- access_key : lt_config [ "lambdatest_auth" ] [ "access_key" ] ,
135- type : "cypress"
136- } ) ;
137- run_test (
138- payload ,
139- env ,
140- lt_config . run_settings . reject_unauthorized
141- )
142- . then ( function ( session_id ) {
143- if ( ! lt_config [ "run_settings" ] [ "retry_failed" ] ) {
144- delete_archive ( project_file ) ;
145- }
146- delete_archive ( file_obj [ "name" ] ) ;
147- //listen to control+c signal and stop tests
148- process . on ( "SIGINT" , async ( ) => {
149- try {
150- console . log (
151- "Control+c signal received.\nTrying to Terminate the processes"
152- ) ;
153- await builds . stop_cypress_session (
154- lt_config ,
155- session_id ,
156- env
157- ) ;
158- resolve ( 0 ) ;
159- } catch ( e ) {
160- console . log ( "Could not exit process. Try Again!!!" ) ;
103+ converter ( lt_config , "he_conv.yaml" ) . then ( function ( ) {
104+ console . log ( "json converted to YAML" )
105+ archive
106+ . archive_project ( lt_config )
107+ . then ( function ( file_obj ) {
108+ project_file = file_obj [ "name" ] ;
109+ lt_config [ "run_settings" ] [ "project_file" ] = project_file ;
110+ //upload the project and get the project link
111+ uploader
112+ . upload_zip ( lt_config , file_obj [ "name" ] , "project" , env )
113+ . then ( async function ( resp ) {
114+ // TODO: remove hard check for undefined. handle it using nested promise rejection
115+ if ( resp == undefined ) {
116+ console . log (
117+ "Either your creds are invalid or something is wrong with the configs provided"
118+ ) ;
119+ return ;
120+ }
121+ //add project link in lt config
122+ project_url = resp [ "value" ] [ "message" ] . split ( "?" ) [ 0 ] . split ( "/" ) ;
123+ project_url = project_url [ project_url . length - 1 ] ;
124+ lt_config [ "run_settings" ] [ "project_url" ] = project_url ;
125+ lt_config [ "test_suite" ] = batches [ 0 ] ;
126+ archive
127+ . archive_batch ( lt_config , batches [ 0 ] , env )
128+ . then ( async function ( file_obj ) {
129+ uploader
130+ . upload_zip ( lt_config , file_obj [ "name" ] , "tests" , env )
131+ . then ( async function ( resp ) {
132+ var payload = JSON . stringify ( {
133+ payload : {
134+ test_file : resp [ "value" ] [ "message" ] . split ( "?" ) [ 0 ] ,
135+ } ,
136+ username : lt_config [ "lambdatest_auth" ] [ "username" ] ,
137+ access_key : lt_config [ "lambdatest_auth" ] [ "access_key" ] ,
138+ type : "cypress"
139+ } ) ;
140+ run_test (
141+ payload ,
142+ env ,
143+ lt_config . run_settings . reject_unauthorized
144+ )
145+ . then ( function ( session_id ) {
146+ if ( ! lt_config [ "run_settings" ] [ "retry_failed" ] ) {
147+ delete_archive ( project_file ) ;
161148 }
162- } ) ;
163- if (
164- lt_config [ "run_settings" ] [ "sync" ] == true ||
165- ( lt_config [ "tunnel_settings" ] [ "tunnel" ] && lt_config [ "tunnel_settings" ] [ "autostart" ] ) || ( lt_config [ "run_settings" ] [ "retry_failed" ] == true )
166- ) {
167- console . log ( "Waiting for build to finish..." ) ;
168- poller . update_status ( true ) ;
169- poller . poll_build ( lt_config , session_id , env )
170- . then ( function ( result ) {
171- const { exit_code, build_info } = result ;
172- if ( lt_config [ "run_settings" ] [ "retry_failed" ] == true && build_info != null ) {
173- let failed_test_suites = [ ] ;
174- for ( i = 0 ; i < build_info [ "data" ] . length ; i ++ ) {
175- if ( build_info [ "data" ] [ i ] [ "status_ind" ] == "failed" ) {
176- let failed_spec = findSpecFile ( lt_config [ "test_suite" ] , build_info [ "data" ] [ i ] )
177- let failed_suite = {
178- spec_file : failed_spec ,
179- path : build_info [ "data" ] [ i ] [ "path" ] ,
180- browser : build_info [ "data" ] [ i ] [ "browser" ] ,
181- version : build_info [ "data" ] [ i ] [ "version" ] ,
182- platform : build_info [ "data" ] [ i ] [ "platform" ]
149+ delete_archive ( file_obj [ "name" ] ) ;
150+ //listen to control+c signal and stop tests
151+ process . on ( "SIGINT" , async ( ) => {
152+ try {
153+ console . log (
154+ "Control+c signal received.\nTrying to Terminate the processes"
155+ ) ;
156+ await builds . stop_cypress_session (
157+ lt_config ,
158+ session_id ,
159+ env
160+ ) ;
161+ resolve ( 0 ) ;
162+ } catch ( e ) {
163+ console . log ( "Could not exit process. Try Again!!!" ) ;
164+ }
165+ } ) ;
166+ if (
167+ lt_config [ "run_settings" ] [ "sync" ] == true ||
168+ ( lt_config [ "tunnel_settings" ] [ "tunnel" ] && lt_config [ "tunnel_settings" ] [ "autostart" ] ) || ( lt_config [ "run_settings" ] [ "retry_failed" ] == true )
169+ ) {
170+ console . log ( "Waiting for build to finish..." ) ;
171+ poller . update_status ( true ) ;
172+ poller . poll_build ( lt_config , session_id , env )
173+ . then ( function ( result ) {
174+ const { exit_code, build_info } = result ;
175+ if ( lt_config [ "run_settings" ] [ "retry_failed" ] == true && build_info != null ) {
176+ let failed_test_suites = [ ] ;
177+ for ( i = 0 ; i < build_info [ "data" ] . length ; i ++ ) {
178+ if ( build_info [ "data" ] [ i ] [ "status_ind" ] == "failed" ) {
179+ let failed_spec = findSpecFile ( lt_config [ "test_suite" ] , build_info [ "data" ] [ i ] )
180+ let failed_suite = {
181+ spec_file : failed_spec ,
182+ path : build_info [ "data" ] [ i ] [ "path" ] ,
183+ browser : build_info [ "data" ] [ i ] [ "browser" ] ,
184+ version : build_info [ "data" ] [ i ] [ "version" ] ,
185+ platform : build_info [ "data" ] [ i ] [ "platform" ]
186+ }
187+ failed_test_suites . push ( failed_suite ) ;
183188 }
184- failed_test_suites . push ( failed_suite ) ;
185189 }
186- }
187- if ( failed_test_suites . length > 0 ) {
188- console . log ( "Retrying failed tests." )
189- let batches = [ failed_test_suites ]
190- retry_run ( lt_config , batches , env )
191- . then ( function ( exit_code ) {
192- if ( exit_code ) {
193- console . log ( "retried failed tests ended with exit code " + exit_code ) ;
194- }
195- resolve ( exit_code ) ;
196- } )
197- . catch ( function ( error ) {
198- console . log ( error ) ;
199- resolve ( 1 ) ;
200- } ) ;
190+ if ( failed_test_suites . length > 0 ) {
191+ console . log ( "Retrying failed tests." )
192+ let batches = [ failed_test_suites ]
193+ retry_run ( lt_config , batches , env )
194+ . then ( function ( exit_code ) {
195+ if ( exit_code ) {
196+ console . log ( "retried failed tests ended with exit code " + exit_code ) ;
197+ }
198+ resolve ( exit_code ) ;
199+ } )
200+ . catch ( function ( error ) {
201+ console . log ( error ) ;
202+ resolve ( 1 ) ;
203+ } ) ;
204+ } else {
205+ resolve ( exit_code ) ;
206+ }
201207 } else {
202208 resolve ( exit_code ) ;
203209 }
204- } else {
205- resolve ( exit_code ) ;
206- }
207- } )
208- . catch ( function ( err ) {
209- console . log (
210- "Some error occured in getting build updates" ,
211- err . message
212- ) ;
213- } ) ;
214- } else {
215- resolve ( 0 ) ;
216- }
217- } )
218- . catch ( function ( err ) {
219- console . log ( "Error occured while creating tests" , err ) ;
220- } ) ;
221- } )
222- . catch ( function ( err ) {
223- delete_archive ( file_obj [ "name" ] ) ;
224- console . log ( "Error occured while uploading files " , err ) ;
225- } ) ;
226- } )
227- . catch ( function ( err ) {
228- console . log ( "Not able to archive the batch of test files" , err ) ;
229- } ) ;
230- } )
231- . catch ( function ( err ) {
232- console . log ( err ) ;
233- archive . delete_archive ( project_file ) ;
234- reject ( err ) ;
235- } ) ;
236- } )
237- . catch ( function ( err ) {
238- console . log ( "Unable to archive the project" ) ;
239- console . log ( err ) ;
240- reject ( err ) ;
241- } ) ;
210+ } )
211+ . catch ( function ( err ) {
212+ console . log (
213+ "Some error occured in getting build updates" ,
214+ err . message
215+ ) ;
216+ } ) ;
217+ } else {
218+ resolve ( 0 ) ;
219+ }
220+ } )
221+ . catch ( function ( err ) {
222+ console . log ( "Error occured while creating tests" , err ) ;
223+ } ) ;
224+ } )
225+ . catch ( function ( err ) {
226+ delete_archive ( file_obj [ "name" ] ) ;
227+ console . log ( "Error occured while uploading files " , err ) ;
228+ } ) ;
229+ } )
230+ . catch ( function ( err ) {
231+ console . log ( "Not able to archive the batch of test files" , err ) ;
232+ } ) ;
233+ } )
234+ . catch ( function ( err ) {
235+ console . log ( err ) ;
236+ archive . delete_archive ( project_file ) ;
237+ reject ( err ) ;
238+ } ) ;
239+ } )
240+ . catch ( function ( err ) {
241+ console . log ( "Unable to archive the project" ) ;
242+ console . log ( err ) ;
243+ reject ( err ) ;
244+ } ) ;
245+ } ) ;
242246 } ) ;
243247}
244248
0 commit comments