1
1
'use strict' ;
2
- const fs = require ( 'fs' ) ;
3
-
4
2
const archiver = require ( "../helpers/archiver" ) ,
5
3
zipUploader = require ( "../helpers/zipUpload" ) ,
6
4
build = require ( "../helpers/build" ) ,
7
5
logger = require ( "../helpers/logger" ) . winstonLogger ,
8
6
config = require ( "../helpers/config" ) ,
9
7
capabilityHelper = require ( "../helpers/capabilityHelper" ) ,
10
8
Constants = require ( "../helpers/constants" ) ,
11
- utils = require ( "../helpers/utils" ) ;
9
+ utils = require ( "../helpers/utils" ) ,
10
+ fileHelpers = require ( "../helpers/fileHelpers" ) ;
12
11
13
12
module . 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 ) {
28
13
let bsConfigPath = process . cwd ( ) + args . cf ;
29
14
30
- utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
15
+ return utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
31
16
utils . setUsageReportingFlag ( bsConfig , args . disableUsageReporting ) ;
32
17
33
18
// Validate browserstack.json values
34
- capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
19
+ return capabilityHelper . validate ( bsConfig ) . then ( function ( validated ) {
35
20
logger . info ( validated ) ;
36
21
37
22
// 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 ) {
39
24
40
25
// Uploaded zip file
41
- zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
26
+ return zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( function ( zip ) {
42
27
43
28
// Create build
44
- build . createBuild ( bsConfig , zip ) . then ( function ( message ) {
29
+ return build . createBuild ( bsConfig , zip ) . then ( function ( message ) {
45
30
logger . info ( message ) ;
46
31
utils . sendUsageReport ( bsConfig , args , message , Constants . messageTypes . SUCCESS , null ) ;
47
32
return ;
@@ -52,19 +37,19 @@ function runCypress(args) {
52
37
} ) ;
53
38
} ) . catch ( function ( err ) {
54
39
// 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 ) ;
57
42
utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
58
43
} ) . finally ( function ( ) {
59
- deleteZip ( ) ;
44
+ fileHelpers . deleteZip ( ) ;
60
45
} ) ;
61
46
} ) . catch ( function ( err ) {
62
47
// Zipping failed
63
48
logger . error ( err ) ;
64
49
logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
65
50
utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
66
51
try {
67
- deleteZip ( ) ;
52
+ fileHelpers . deleteZip ( ) ;
68
53
} catch ( err ) {
69
54
utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
70
55
}
@@ -81,5 +66,5 @@ function runCypress(args) {
81
66
logger . error ( err ) ;
82
67
utils . setUsageReportingFlag ( null , args . disableUsageReporting ) ;
83
68
utils . sendUsageReport ( null , args , err . message , Constants . messageTypes . ERROR , utils . getErrorCodeFromErr ( err ) ) ;
84
- } )
69
+ } ) ;
85
70
}
0 commit comments