@@ -9,14 +9,22 @@ const archiver = require("../helpers/archiver"),
9
9
utils = require ( "../helpers/utils" ) ,
10
10
fileHelpers = require ( "../helpers/fileHelpers" ) ,
11
11
syncRunner = require ( "../helpers/syncRunner" ) ,
12
- reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ;
12
+ checkUploaded = require ( "../helpers/checkUploaded" ) ,
13
+ reportGenerator = require ( '../helpers/reporterHTML' ) . reportGenerator ,
14
+ { initTimeComponents, markBlockStart, markBlockEnd, getTimeComponents} = require ( '../helpers/timeComponents' ) ;
13
15
14
16
module . exports = function run ( args ) {
15
17
let bsConfigPath = utils . getConfigPath ( args . cf ) ;
16
18
//Delete build_results.txt from log folder if already present.
19
+ initTimeComponents ( ) ;
20
+ markBlockStart ( 'deleteOldResults' ) ;
17
21
utils . deleteResults ( ) ;
22
+ markBlockEnd ( 'deleteOldResults' ) ;
18
23
24
+ markBlockStart ( 'validateBstackJson' ) ;
19
25
return utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
26
+ markBlockEnd ( 'validateBstackJson' ) ;
27
+ markBlockStart ( 'setConfig' ) ;
20
28
utils . setUsageReportingFlag ( bsConfig , args . disableUsageReporting ) ;
21
29
22
30
utils . setDefaults ( bsConfig , args ) ;
@@ -39,6 +47,9 @@ module.exports = function run(args) {
39
47
// accept the env list from command line and set it
40
48
utils . setTestEnvs ( bsConfig , args ) ;
41
49
50
+ // accept the system env list from bsconf and set it
51
+ utils . setSystemEnvs ( bsConfig ) ;
52
+
42
53
//accept the local from env variable if provided
43
54
utils . setLocal ( bsConfig , args ) ;
44
55
@@ -54,91 +65,137 @@ module.exports = function run(args) {
54
65
// run test in headed mode
55
66
utils . setHeaded ( bsConfig , args ) ;
56
67
68
+ // set the no-wrap
69
+ utils . setNoWrap ( bsConfig , args ) ;
70
+ markBlockEnd ( 'setConfig' ) ;
71
+
57
72
// Validate browserstack.json values and parallels specified via arguments
73
+ markBlockStart ( 'validateConfig' ) ;
58
74
return capabilityHelper . validate ( bsConfig , args ) . then ( function ( cypressJson ) {
59
-
75
+ markBlockEnd ( 'validateConfig' ) ;
76
+ markBlockStart ( 'preArchiveSteps' ) ;
60
77
//get the number of spec files
61
78
let specFiles = utils . getNumberOfSpecFiles ( bsConfig , args , cypressJson ) ;
62
79
63
80
// accept the number of parallels
64
81
utils . setParallels ( bsConfig , args , specFiles . length ) ;
65
82
66
- // Archive the spec files
67
- return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude ) . then ( function ( data ) {
68
-
69
- // Uploaded zip file
70
- return zipUploader . zipUpload ( bsConfig , config . fileName ) . then ( async function ( zip ) {
71
- // Create build
72
-
73
- //setup Local Testing
74
- let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
75
-
76
- return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
77
- let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
78
- let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
79
- utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
80
- 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 ) ) {
81
- logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
82
- }
83
-
84
- if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
85
- let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version )
86
- logger . warn ( versionMessage ) ;
87
- }
88
-
89
- if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
90
- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
91
- logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
92
- }
93
-
94
- if ( args . sync ) {
95
- syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
96
-
97
- // stop the Local instance
98
- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
99
-
100
- // Generate custom report!
101
- reportGenerator ( bsConfig , data . build_id , args , function ( ) {
102
- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
103
- utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
83
+ // warn if specFiles cross our limit
84
+ utils . warnSpecLimit ( bsConfig , args , specFiles ) ;
85
+ markBlockEnd ( 'preArchiveSteps' ) ;
86
+ markBlockStart ( 'checkAlreadyUploaded' ) ;
87
+ return checkUploaded . checkUploadedMd5 ( bsConfig , args ) . then ( function ( md5data ) {
88
+ markBlockEnd ( 'checkAlreadyUploaded' ) ;
89
+
90
+ // Archive the spec files
91
+ markBlockStart ( 'zip' ) ;
92
+ markBlockStart ( 'zip.archive' ) ;
93
+ return archiver . archive ( bsConfig . run_settings , config . fileName , args . exclude , md5data ) . then ( function ( data ) {
94
+ markBlockEnd ( 'zip.archive' ) ;
95
+
96
+ // Uploaded zip file
97
+ markBlockStart ( 'zip.zipUpload' ) ;
98
+ return zipUploader . zipUpload ( bsConfig , config . fileName , md5data ) . then ( async function ( zip ) {
99
+ markBlockEnd ( 'zip.zipUpload' ) ;
100
+ markBlockEnd ( 'zip' ) ;
101
+ // Create build
102
+
103
+ //setup Local Testing
104
+ markBlockStart ( 'localSetup' ) ;
105
+ let bs_local = await utils . setupLocalTesting ( bsConfig , args ) ;
106
+ markBlockEnd ( 'localSetup' ) ;
107
+ markBlockStart ( 'createBuild' ) ;
108
+ return build . createBuild ( bsConfig , zip ) . then ( function ( data ) {
109
+ markBlockEnd ( 'createBuild' ) ;
110
+ markBlockEnd ( 'total' ) ;
111
+ let message = `${ data . message } ! ${ Constants . userMessages . BUILD_CREATED } with build id: ${ data . build_id } ` ;
112
+ let dashboardLink = `${ Constants . userMessages . VISIT_DASHBOARD } ${ data . dashboard_url } ` ;
113
+ utils . exportResults ( data . build_id , `${ config . dashboardUrl } ${ data . build_id } ` ) ;
114
+ 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 ) ) {
115
+ logger . warn ( Constants . userMessages . NO_PARALLELS ) ;
116
+ }
117
+
118
+ if ( bsConfig . run_settings . cypress_version && bsConfig . run_settings . cypress_version !== data . cypress_version ) {
119
+ if ( bsConfig . run_settings . cypress_version . toString ( ) . match ( Constants . LATEST_VERSION_SYNTAX_REGEX ) ) {
120
+ let versionMessage = utils . latestSyntaxToActualVersionMessage ( bsConfig . run_settings . cypress_version , data . cypress_version ) ;
121
+ logger . info ( versionMessage ) ;
122
+ } else {
123
+ let versionMessage = utils . versionChangedMessage ( bsConfig . run_settings . cypress_version , data . cypress_version ) ;
124
+ logger . warn ( versionMessage ) ;
125
+ }
126
+ }
127
+
128
+ if ( ! args . disableNpmWarning && bsConfig . run_settings . npm_dependencies && Object . keys ( bsConfig . run_settings . npm_dependencies ) . length <= 0 ) {
129
+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES ) ;
130
+ logger . warn ( Constants . userMessages . NO_NPM_DEPENDENCIES_READ_MORE ) ;
131
+ }
132
+
133
+ if ( args . sync ) {
134
+ syncRunner . pollBuildStatus ( bsConfig , data ) . then ( async ( exitCode ) => {
135
+
136
+ // stop the Local instance
137
+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
138
+
139
+ // Generate custom report!
140
+ reportGenerator ( bsConfig , data . build_id , args , function ( ) {
141
+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
142
+ utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
143
+ } ) ;
104
144
} ) ;
105
- } ) ;
106
- }
107
-
108
- logger . info ( message ) ;
109
- logger . info ( dashboardLink ) ;
110
- if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
111
- utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null ) ;
112
- return ;
113
- } ) . catch ( async function ( err ) {
114
- // Build creation failed
145
+ }
146
+
147
+ logger . info ( message ) ;
148
+ logger . info ( dashboardLink ) ;
149
+ if ( ! args . sync ) logger . info ( Constants . userMessages . EXIT_SYNC_CLI_MESSAGE . replace ( "<build-id>" , data . build_id ) ) ;
150
+ let dataToSend = {
151
+ time_components : getTimeComponents ( ) ,
152
+ build_id : data . build_id ,
153
+ } ;
154
+ if ( bsConfig && bsConfig . connection_settings ) {
155
+ if ( bsConfig . connection_settings . local_mode ) {
156
+ dataToSend . local_mode = bsConfig . connection_settings . local_mode ;
157
+ }
158
+ if ( bsConfig . connection_settings . usedAutoLocal ) {
159
+ dataToSend . used_auto_local = bsConfig . connection_settings . usedAutoLocal ;
160
+ }
161
+ }
162
+ utils . sendUsageReport ( bsConfig , args , `${ message } \n${ dashboardLink } ` , Constants . messageTypes . SUCCESS , null , dataToSend ) ;
163
+ return ;
164
+ } ) . catch ( async function ( err ) {
165
+ // Build creation failed
166
+ logger . error ( err ) ;
167
+ // stop the Local instance
168
+ await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
169
+
170
+ utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
171
+ } ) ;
172
+ } ) . catch ( function ( err ) {
173
+ // Zip Upload failed | Local Start failed
115
174
logger . error ( err ) ;
116
- // stop the Local instance
117
- await utils . stopLocalBinary ( bsConfig , bs_local , args ) ;
118
-
119
- utils . sendUsageReport ( bsConfig , args , err , Constants . messageTypes . ERROR , 'build_failed' ) ;
175
+ if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
176
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
177
+ } else {
178
+ logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
179
+ fileHelpers . deleteZip ( ) ;
180
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
181
+ }
120
182
} ) ;
121
183
} ) . catch ( function ( err ) {
122
- // Zip Upload failed | Local Start failed
184
+ // Zipping failed
123
185
logger . error ( err ) ;
124
- if ( err === Constants . userMessages . LOCAL_START_FAILED ) {
125
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . LOCAL_START_FAILED } ` , Constants . messageTypes . ERROR , 'local_start_failed' ) ;
126
- } else {
127
- logger . error ( Constants . userMessages . ZIP_UPLOAD_FAILED ) ;
186
+ logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
187
+ utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
188
+ try {
128
189
fileHelpers . deleteZip ( ) ;
129
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . ZIP_UPLOAD_FAILED } ` , Constants . messageTypes . ERROR , 'zip_upload_failed' ) ;
190
+ } catch ( err ) {
191
+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
130
192
}
131
193
} ) ;
132
194
} ) . catch ( function ( err ) {
133
- // Zipping failed
195
+ // md5 check failed
134
196
logger . error ( err ) ;
135
- logger . error ( Constants . userMessages . FAILED_TO_ZIP ) ;
136
- utils . sendUsageReport ( bsConfig , args , `${ err } \n${ Constants . userMessages . FAILED_TO_ZIP } ` , Constants . messageTypes . ERROR , 'zip_creation_failed' ) ;
137
- try {
138
- fileHelpers . deleteZip ( ) ;
139
- } catch ( err ) {
140
- utils . sendUsageReport ( bsConfig , args , Constants . userMessages . ZIP_DELETE_FAILED , Constants . messageTypes . ERROR , 'zip_deletion_failed' ) ;
141
- }
197
+ logger . error ( Constants . userMessages . FAILED_MD5_CHECK ) ;
198
+ utils . sendUsageReport ( bsConfig , args , Constants . userMessages . MD5_CHECK_FAILED , Constants . messageTypes . ERROR , 'zip_already_uploaded_failed' ) ;
142
199
} ) ;
143
200
} ) . catch ( function ( err ) {
144
201
// browerstack.json is not valid
0 commit comments