@@ -9,14 +9,22 @@ const archiver = require("../helpers/archiver"),
99 utils = require ( "../helpers/utils" ) ,
1010 fileHelpers = require ( "../helpers/fileHelpers" ) ,
1111 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' ) ;
1315
1416module . exports = function run ( args ) {
1517 let bsConfigPath = utils . getConfigPath ( args . cf ) ;
1618 //Delete build_results.txt from log folder if already present.
19+ initTimeComponents ( ) ;
20+ markBlockStart ( 'deleteOldResults' ) ;
1721 utils . deleteResults ( ) ;
22+ markBlockEnd ( 'deleteOldResults' ) ;
1823
24+ markBlockStart ( 'validateBstackJson' ) ;
1925 return utils . validateBstackJson ( bsConfigPath ) . then ( function ( bsConfig ) {
26+ markBlockEnd ( 'validateBstackJson' ) ;
27+ markBlockStart ( 'setConfig' ) ;
2028 utils . setUsageReportingFlag ( bsConfig , args . disableUsageReporting ) ;
2129
2230 utils . setDefaults ( bsConfig , args ) ;
@@ -39,6 +47,9 @@ module.exports = function run(args) {
3947 // accept the env list from command line and set it
4048 utils . setTestEnvs ( bsConfig , args ) ;
4149
50+ // accept the system env list from bsconf and set it
51+ utils . setSystemEnvs ( bsConfig ) ;
52+
4253 //accept the local from env variable if provided
4354 utils . setLocal ( bsConfig , args ) ;
4455
@@ -54,91 +65,137 @@ module.exports = function run(args) {
5465 // run test in headed mode
5566 utils . setHeaded ( bsConfig , args ) ;
5667
68+ // set the no-wrap
69+ utils . setNoWrap ( bsConfig , args ) ;
70+ markBlockEnd ( 'setConfig' ) ;
71+
5772 // Validate browserstack.json values and parallels specified via arguments
73+ markBlockStart ( 'validateConfig' ) ;
5874 return capabilityHelper . validate ( bsConfig , args ) . then ( function ( cypressJson ) {
59-
75+ markBlockEnd ( 'validateConfig' ) ;
76+ markBlockStart ( 'preArchiveSteps' ) ;
6077 //get the number of spec files
6178 let specFiles = utils . getNumberOfSpecFiles ( bsConfig , args , cypressJson ) ;
6279
6380 // accept the number of parallels
6481 utils . setParallels ( bsConfig , args , specFiles . length ) ;
6582
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+ } ) ;
104144 } ) ;
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
115174 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+ }
120182 } ) ;
121183 } ) . catch ( function ( err ) {
122- // Zip Upload failed | Local Start failed
184+ // Zipping failed
123185 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 {
128189 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' ) ;
130192 }
131193 } ) ;
132194 } ) . catch ( function ( err ) {
133- // Zipping failed
195+ // md5 check failed
134196 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' ) ;
142199 } ) ;
143200 } ) . catch ( function ( err ) {
144201 // browerstack.json is not valid
0 commit comments