@@ -7,6 +7,7 @@ var config = require('../helpers/config');
7
7
var capabilityHelper = require ( "../helpers/capabilityHelper" ) ;
8
8
var fs = require ( 'fs' ) ;
9
9
const Constants = require ( '../helpers/constants' ) ;
10
+ const fileHelpers = require ( '../helpers/fileHelpers' ) ;
10
11
11
12
module . exports = function run ( args ) {
12
13
return runCypress ( args ) ;
@@ -18,45 +19,51 @@ function deleteZip() {
18
19
logger . log ( Constants . userMessages . ZIP_DELETE_FAILED ) ;
19
20
} else {
20
21
logger . log ( Constants . userMessages . ZIP_DELETED ) ;
21
- }
22
+ }
22
23
} ) ;
23
24
}
24
25
25
26
function runCypress ( args ) {
26
27
let bsConfigPath = process . cwd ( ) + args . cf ;
27
28
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 ) ;
29
32
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
+ } ) ;
40
54
} ) . 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 ( ) ;
43
59
} ) ;
44
60
} ) . catch ( function ( err ) {
45
- // Zip Upload failed
61
+ // browerstack.json is not valid
46
62
logger . error ( err )
47
- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED )
48
- } ) . finally ( function ( ) {
49
- deleteZip ( ) ;
63
+ logger . error ( Constants . validationMessages . NOT_VALID )
50
64
} ) ;
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
+ }
61
68
} ) ;
62
69
}
0 commit comments