11'use strict' ;
2- const fs = require ( 'fs' ) ;
3-
42const archiver = require ( "../helpers/archiver" ) ,
53 zipUploader = require ( "../helpers/zipUpload" ) ,
64 build = require ( "../helpers/build" ) ,
75 logger = require ( "../helpers/logger" ) . winstonLogger ,
86 config = require ( "../helpers/config" ) ,
97 capabilityHelper = require ( "../helpers/capabilityHelper" ) ,
108 Constants = require ( "../helpers/constants" ) ,
11- utils = require ( "../helpers/utils" ) ;
9+ utils = require ( "../helpers/utils" ) ,
10+ fileHelpers = require ( "../helpers/fileHelpers" ) ;
1211
1312module . exports = function run ( args ) {
14- return runCypress ( args ) ;
15- }
16-
17- function deleteZip ( ) {
18- fs . unlink ( config . fileName , function ( err ) {
19- if ( err ) {
20- logger . info ( Constants . userMessages . ZIP_DELETE_FAILED ) ;
21- } else {
22- logger . info ( Constants . userMessages . ZIP_DELETED ) ;
23- }
24- } ) ;
25- }
26-
27- function runCypress ( args ) {
2813 let bsConfigPath = process . cwd ( ) + args . cf ;
2914
30- utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
15+ return utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
3116 utils . setUsageReportingFlag ( bsConfig , args . disableUsageReporting ) ;
3217
3318 // Validate browserstack.json values
34- capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
19+ return capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
3520 logger . info ( validated ) ;
3621
3722 // Archive the spec files
38- archiver . archive ( bsConfig . run_settings , config . fileName ) . then ( function ( data ) {
23+ return archiver . archive ( bsConfig . run_settings , config . fileName ) . then ( function ( data ) {
3924
4025 // Uploaded zip file
41- zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
26+ return zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
4227
4328 // Create build
44- build . createBuild ( bsConfig , zip ) . then ( function ( message ) {
29+ return build . createBuild ( bsConfig , zip ) . then ( function ( message ) {
4530 logger . info ( message ) ;
4631 utils . sendUsageReport ( bsConfig , args , message , Constants . messageTypes . SUCCESS , null ) ;
4732 return ;
@@ -52,19 +37,19 @@ function runCypress(args) {
5237 } ) ;
5338 } ) . catch ( function ( err ) {
5439 // Zip Upload failed
55- logger . error ( err )
56- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED )
40+ logger . error ( err ) ;
41+ logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
5742 utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
5843 } ) . finally ( function ( ) {
59- deleteZip ( ) ;
44+ fileHelpers . deleteZip ( ) ;
6045 } ) ;
6146 } ) . catch ( function ( err ) {
6247 // Zipping failed
6348 logger . error ( err ) ;
6449 logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
6550 utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
6651 try {
67- deleteZip ( ) ;
52+ fileHelpers . deleteZip ( ) ;
6853 } catch ( err ) {
6954 utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
7055 }
@@ -81,5 +66,5 @@ function runCypress(args) {
8166 logger . error ( err ) ;
8267 utils . setUsageReportingFlag ( null , args . disableUsageReporting ) ;
8368 utils . sendUsageReport ( null , args , err . message , Constants . messageTypes . ERROR , utils . getErrorCodeFromErr ( err ) ) ;
84- } )
69+ } ) ;
8570}
0 commit comments