@@ -7,6 +7,7 @@ var config = require('../helpers/config');
77var capabilityHelper = require ( "../helpers/capabilityHelper" ) ;
88var fs = require ( 'fs' ) ;
99const Constants = require ( '../helpers/constants' ) ;
10+ const fileHelpers = require ( '../helpers/fileHelpers' ) ;
1011
1112module . exports = function run ( args ) {
1213 return runCypress ( args ) ;
@@ -18,45 +19,51 @@ function deleteZip() {
1819 logger . log ( Constants . userMessages . ZIP_DELETE_FAILED ) ;
1920 } else {
2021 logger . log ( Constants . userMessages . ZIP_DELETED ) ;
21- }
22+ }
2223 } ) ;
2324}
2425
2526function runCypress ( args ) {
2627 let bsConfigPath = process . cwd ( ) + args . cf ;
2728 logger . log ( `Reading config from ${ args . cf } ` ) ;
28- var bsConfig = require ( bsConfigPath ) ;
29+ fileHelpers . fileExists ( bsConfigPath , ( configExists ) => {
30+ if ( configExists ) {
31+ var bsConfig = require ( bsConfigPath ) ;
2932
30- // Validate browserstack.json
31- capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
32- logger . log ( validated ) ;
33- // Archive the spec files
34- archiver . archive ( bsConfig . run_settings , config . fileName ) . then ( function ( data ) {
35- // Uploaded zip file
36- zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
37- // Create build
38- build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
39- return ;
33+ // Validate browserstack.json
34+ capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
35+ logger . log ( validated ) ;
36+ // Archive the spec files
37+ archiver . archive ( bsConfig . run_settings , config . fileName ) . then ( function ( data ) {
38+ // Uploaded zip file
39+ zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
40+ // Create build
41+ build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
42+ return ;
43+ } ) . catch ( function ( err ) {
44+ // Build creation failed
45+ logger . error ( Constants . userMessages . BUILD_FAILED )
46+ } ) ;
47+ } ) . catch ( function ( err ) {
48+ // Zip Upload failed
49+ logger . error ( err )
50+ logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED )
51+ } ) . finally ( function ( ) {
52+ deleteZip ( ) ;
53+ } ) ;
4054 } ) . catch ( function ( err ) {
41- // Build creation failed
42- logger . error ( Constants . userMessages . BUILD_FAILED )
55+ // Zipping failed
56+ logger . error ( err )
57+ logger . error ( Constants . userMessages . FAILED_TO_ZIP )
58+ deleteZip ( ) ;
4359 } ) ;
4460 } ) . catch ( function ( err ) {
45- // Zip Upload failed
61+ // browerstack.json is not valid
4662 logger . error ( err )
47- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED )
48- } ) . finally ( function ( ) {
49- deleteZip ( ) ;
63+ logger . error ( Constants . validationMessages . NOT_VALID )
5064 } ) ;
51- } ) . catch ( function ( err ) {
52- // Zipping failed
53- logger . error ( err )
54- logger . error ( Constants . userMessages . FAILED_TO_ZIP )
55- deleteZip ( ) ;
56- } ) ;
57- } ) . catch ( function ( err ) {
58- // browerstack.json is not valid
59- logger . error ( err )
60- logger . error ( Constants . validationMessages . NOT_VALID )
65+ } else {
66+ logger . error ( 'Could not find browserstack.json, you can create it by running `browserstack-cypress init`' ) ;
67+ }
6168 } ) ;
6269}
0 commit comments