@@ -10,6 +10,7 @@ const archiver = require("../helpers/archiver"),
1010 fileHelpers = require ( "../helpers/fileHelpers" ) ,
1111 syncRunner = require ( "../helpers/syncRunner" ) ,
1212 checkUploaded = require ( "../helpers/checkUploaded" ) ,
13+ packageInstaller = require ( "../helpers/packageInstaller" ) ,
1314 reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ,
1415 { initTimeComponents, instrumentEventTime, markBlockStart, markBlockEnd, getTimeComponents} = require ( '../helpers/timeComponents' ) ,
1516 downloadBuildArtifacts = require ( '../helpers/buildArtifacts' ) . downloadBuildArtifacts ,
@@ -103,121 +104,151 @@ module.exports = function run(args) {
103104 return checkUploaded . checkUploadedMd5 ( bsConfig , args , { markBlockStart, markBlockEnd} ) . then ( function ( md5data ) {
104105 markBlockEnd ( 'checkAlreadyUploaded' ) ;
105106
106- // Archive the spec files
107- markBlockStart ( 'zip' ) ;
108- markBlockStart ( 'zip.archive' ) ;
109- return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
110- markBlockEnd ( 'zip.archive' ) ;
111-
112- // Uploaded zip file
113- markBlockStart ( 'zip.zipUpload' ) ;
114- return zipUploader . zipUpload ( bsConfig , config . fileName , md5data ) . then ( async function ( zip ) {
115- markBlockEnd ( 'zip.zipUpload' ) ;
116- markBlockEnd ( 'zip' ) ;
117- // Create build
118-
119- //setup Local Testing
120- markBlockStart ( 'localSetup' ) ;
121- let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
122- markBlockEnd ( 'localSetup' ) ;
123- markBlockStart ( 'createBuild' ) ;
124- return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
125- markBlockEnd ( 'createBuild' ) ;
126- markBlockEnd ( 'total' ) ;
127- utils . setProcessHooks ( data . build_id , bsConfig , bs_local , args ) ;
128- let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
129- let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
130- utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
131- if ( ( utils . isUndefined ( bsConfig . run_settings . parallels ) && utils . isUndefined ( args . parallels ) ) || ( ! utils . isUndefined ( bsConfig . run_settings . parallels ) && bsConfig . run_settings . parallels == Constants . cliMessages . RUN . DEFAULT_PARALLEL_MESSAGE ) ) {
132- logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
133- }
134- if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
135- if ( bsConfig . run_settings . cypress_version . toString ( ) . match ( Constants . LATEST_VERSION_SYNTAX_REGEX ) ) {
136- let versionMessage = utils . latestSyntaxToActualVersionMessage ( bsConfig . run_settings . cypress_version , data . cypress_version , data . framework_upgrade_message ) ;
137- logger . info ( versionMessage ) ;
138- } else {
139- let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version , data . framework_upgrade_message ) ;
140- logger . warn ( versionMessage ) ;
107+ markBlockStart ( 'packageInstaller' ) ;
108+ return packageInstaller . packageWrapper ( bsConfig , config . packageDirName , config . packageFileName , md5data , { markBlockStart, markBlockEnd} ) . then ( function ( packageData ) {
109+ markBlockEnd ( 'packageInstaller' ) ;
110+
111+ // Archive the spec files
112+ markBlockStart ( 'zip' ) ;
113+ markBlockStart ( 'zip.archive' ) ;
114+ return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
115+ markBlockEnd ( 'zip.archive' ) ;
116+
117+ // Uploaded zip file
118+ markBlockStart ( 'zip.zipUpload' ) ;
119+ return zipUploader . zipUpload ( bsConfig , md5data , packageData ) . then ( async function ( zip ) {
120+ markBlockEnd ( 'zip.zipUpload' ) ;
121+ markBlockEnd ( 'zip' ) ;
122+
123+ // Create build
124+ //setup Local Testing
125+ markBlockStart ( 'localSetup' ) ;
126+ let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
127+ markBlockEnd ( 'localSetup' ) ;
128+ markBlockStart ( 'createBuild' ) ;
129+ return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
130+ markBlockEnd ( 'createBuild' ) ;
131+ markBlockEnd ( 'total' ) ;
132+ utils . setProcessHooks ( data . build_id , bsConfig , bs_local , args ) ;
133+ let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
134+ let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
135+ utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
136+ if ( ( utils . isUndefined ( bsConfig . run_settings . parallels ) && utils . isUndefined ( args . parallels ) ) || ( ! utils . isUndefined ( bsConfig . run_settings . parallels ) && bsConfig . run_settings . parallels == Constants . cliMessages . RUN . DEFAULT_PARALLEL_MESSAGE ) ) {
137+ logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
141138 }
142- }
143139
144- if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
145- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
146- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
147- }
140+ if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
141+ if ( bsConfig . run_settings . cypress_version . toString ( ) . match ( Constants . LATEST_VERSION_SYNTAX_REGEX ) ) {
142+ let versionMessage = utils . latestSyntaxToActualVersionMessage ( bsConfig . run_settings . cypress_version , data . cypress_version , data . framework_upgrade_message ) ;
143+ logger . info ( versionMessage ) ;
144+ } else {
145+ let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version , data . framework_upgrade_message ) ;
146+ logger . warn ( versionMessage ) ;
147+ }
148+ }
148149
149- if ( args . sync ) {
150- syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
150+ if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
151+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
152+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
153+ }
151154
152- // stop the Local instance
153- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
154155
155- // waiting for 5 secs for upload to complete (as a safety measure)
156- await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
156+ if ( args . sync ) {
157+ syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
157158
158- // download build artifacts
159- if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
160- await downloadBuildArtifacts ( bsConfig , data . build_id , args ) ;
161- }
159+ // stop the Local instance
160+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
161+
162+ // waiting for 5 secs for upload to complete (as a safety measure)
163+ await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
164+
165+ // download build artifacts
166+ if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
167+ await downloadBuildArtifacts ( bsConfig , data . build_id , args ) ;
168+ }
162169
163- // Generate custom report!
164- reportGenerator ( bsConfig , data . build_id , args , function ( ) {
165- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
166- utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
170+ // Generate custom report!
171+ reportGenerator ( bsConfig , data . build_id , args , function ( ) {
172+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
173+ utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
174+ } ) ;
167175 } ) ;
168- } ) ;
169- } else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
170- logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
171- }
176+ } else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
177+ logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
178+ }
172179
173- logger . info ( message ) ;
174- logger . info ( dashboardLink ) ;
175- if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
176- let dataToSend = {
177- time_components : getTimeComponents ( ) ,
178- unique_id : utils . generateUniqueHash ( ) ,
179- build_id : data . build_id ,
180- } ;
181- if ( bsConfig && bsConfig . connection_settings ) {
182- if ( bsConfig . connection_settings . local_mode ) {
183- dataToSend . local_mode = bsConfig . connection_settings . local_mode ;
180+ logger . info ( message ) ;
181+ logger . info ( dashboardLink ) ;
182+ if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
183+ let dataToSend = {
184+ time_components : getTimeComponents ( ) ,
185+ unique_id : utils . generateUniqueHash ( ) ,
186+ package_error : utils . checkError ( packageData ) ,
187+ checkmd5_error : utils . checkError ( md5data ) ,
188+ build_id : data . build_id ,
189+ } ;
190+ if ( bsConfig && bsConfig . connection_settings ) {
191+ if ( bsConfig . connection_settings . local_mode ) {
192+ dataToSend . local_mode = bsConfig . connection_settings . local_mode ;
193+ }
194+ if ( bsConfig . connection_settings . usedAutoLocal ) {
195+ dataToSend . used_auto_local = bsConfig . connection_settings . usedAutoLocal ;
196+ }
184197 }
185- if ( bsConfig . connection_settings . usedAutoLocal ) {
186- dataToSend . used_auto_local = bsConfig . connection_settings . usedAutoLocal ;
198+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , dataToSend ) ;
199+ return ;
200+ } ) . catch ( async function ( err ) {
201+ // Build creation failed
202+ logger . error ( err ) ;
203+ // stop the Local instance
204+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
205+
206+ utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
207+ process . exitCode = Constants . ERROR_EXIT_CODE ;
208+ } ) ;
209+ } ) . catch ( function ( err ) {
210+ // Zip Upload failed | Local Start failed
211+ logger . error ( err ) ;
212+ if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
213+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
214+ } else {
215+ logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
216+ fileHelpers . deleteZip ( ) ;
217+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
218+ try {
219+ fileHelpers . deletePackageArchieve ( ) ;
220+ } catch ( err ) {
221+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . NPM_DELETE_FAILED , Constants . messageTypes . ERROR , 'npm_deletion_failed' ) ;
187222 }
188223 }
189- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , dataToSend ) ;
190- return ;
191- } ) . catch ( async function ( err ) {
192- // Build creation failed
193- logger . error ( err ) ;
194- // stop the Local instance
195- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
196-
197- utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
198224 process . exitCode = Constants . ERROR_EXIT_CODE ;
199225 } ) ;
200226 } ) . catch ( function ( err ) {
201- // Zip Upload failed | Local Start failed
227+ // Zipping failed
202228 logger . error ( err ) ;
203- if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
204- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
205- } else {
206- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
229+ logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
230+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
231+ try {
207232 fileHelpers . deleteZip ( ) ;
208- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
233+ } catch ( err ) {
234+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
235+ }
236+ try {
237+ fileHelpers . deletePackageArchieve ( ) ;
238+ } catch ( err ) {
239+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . NPM_DELETE_FAILED , Constants . messageTypes . ERROR , 'npm_deletion_failed' ) ;
209240 }
210241 process . exitCode = Constants . ERROR_EXIT_CODE ;
211242 } ) ;
212243 } ) . catch ( function ( err ) {
213- // Zipping failed
244+ // package installer failed
214245 logger . error ( err ) ;
215- logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
216- utils . sendUsageReport ( bsConfig , args , ` ${ err } \n ${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed ' ) ;
246+ logger . error ( Constants . userMessages . FAILED_CREATE_NPM_ARCHIVE ) ;
247+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . FAILED_CREATE_NPM_ARCHIVE , Constants . messageTypes . ERROR , 'npm_package_archive_failed ' ) ;
217248 try {
218- fileHelpers . deleteZip ( ) ;
249+ fileHelpers . deletePackageArchieve ( ) ;
219250 } catch ( err ) {
220- utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed ' ) ;
251+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . NPM_DELETE_FAILED , Constants . messageTypes . ERROR , 'npm_deletion_failed ' ) ;
221252 }
222253 process . exitCode = Constants . ERROR_EXIT_CODE ;
223254 } ) ;
0 commit comments