@@ -36,6 +36,7 @@ const {
3636 checkAccessibilityPlatform,
3737 supportFileCleanup
3838} = require ( '../accessibility-automation/helper' ) ;
39+ const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileContent, atsFileCleanup } = require ( '../helpers/atsHelper' ) ;
3940
4041module . exports = function run ( args , rawArgs ) {
4142
@@ -66,6 +67,8 @@ module.exports = function run(args, rawArgs) {
6667 const [ isTestObservabilitySession , isBrowserstackInfra ] = setTestObservabilityFlags ( bsConfig ) ;
6768 const checkAccessibility = checkAccessibilityPlatform ( bsConfig ) ;
6869 const isAccessibilitySession = bsConfig . run_settings . accessibility || checkAccessibility ;
70+ const turboScaleSession = isTurboScaleSession ( bsConfig ) ;
71+ Constants . turboScaleObj . enabled = turboScaleSession ;
6972
7073 utils . setUsageReportingFlag ( bsConfig , args . disableUsageReporting ) ;
7174
@@ -77,7 +80,7 @@ module.exports = function run(args, rawArgs) {
7780 // accept the access key from command line or env variable if provided
7881 utils . setAccessKey ( bsConfig , args ) ;
7982
80- let buildReportData = ! isBrowserstackInfra ? null : await getInitialDetails ( bsConfig , args , rawArgs ) ;
83+ let buildReportData = ( turboScaleSession || ! isBrowserstackInfra ) ? null : await getInitialDetails ( bsConfig , args , rawArgs ) ;
8184
8285 // accept the build name from command line if provided
8386 utils . setBuildName ( bsConfig , args ) ;
@@ -147,6 +150,29 @@ module.exports = function run(args, rawArgs) {
147150 if ( isAccessibilitySession && isBrowserstackInfra ) {
148151 await createAccessibilityTestRun ( bsConfig ) ;
149152 }
153+
154+ if ( turboScaleSession ) {
155+ // Local is only required in case user is running on trial grid and wants to access private website.
156+ // Even then, it will be spawned separately via browserstack-cli ats connect-grid command and not via browserstack-cypress-cli
157+ // Hence whenever running on ATS, need to make local as false
158+ bsConfig . connection_settings . local = false ;
159+
160+ const gridDetails = await getTurboScaleGridDetails ( bsConfig , args , rawArgs ) ;
161+
162+ if ( gridDetails && Object . keys ( gridDetails ) . length > 0 ) {
163+ Constants . turboScaleObj . gridDetails = gridDetails ;
164+ Constants . turboScaleObj . gridUrl = gridDetails . cypressUrl ;
165+ Constants . turboScaleObj . uploadUrl = gridDetails . cypressUrl + '/upload' ;
166+ Constants . turboScaleObj . buildUrl = gridDetails . cypressUrl + '/build' ;
167+
168+ logger . debug ( `Automate TurboScale Grid URL set to ${ gridDetails . url } ` ) ;
169+
170+ patchCypressConfigFileContent ( bsConfig ) ;
171+ } else {
172+ process . exitCode = Constants . ERROR_EXIT_CODE ;
173+ return ;
174+ }
175+ }
150176 }
151177
152178 const { packagesInstalled } = ! isBrowserstackInfra ? false : await packageInstaller . packageSetupAndInstaller ( bsConfig , config . packageDirName , { markBlockStart, markBlockEnd} ) ;
@@ -186,7 +212,7 @@ module.exports = function run(args, rawArgs) {
186212
187213 //get the number of spec files
188214 markBlockStart ( 'getNumberOfSpecFiles' ) ;
189- let specFiles = utils . getNumberOfSpecFiles ( bsConfig , args , cypressConfigFile ) ;
215+ let specFiles = utils . getNumberOfSpecFiles ( bsConfig , args , cypressConfigFile , turboScaleSession ) ;
190216 markBlockEnd ( 'getNumberOfSpecFiles' ) ;
191217
192218 bsConfig [ 'run_settings' ] [ 'video_config' ] = utils . getVideoConfig ( cypressConfigFile , bsConfig ) ;
@@ -251,6 +277,11 @@ module.exports = function run(args, rawArgs) {
251277 if ( process . env . BROWSERSTACK_TEST_ACCESSIBILITY === 'true' ) {
252278 supportFileCleanup ( ) ;
253279 }
280+
281+ if ( turboScaleSession ) {
282+ atsFileCleanup ( bsConfig ) ;
283+ }
284+
254285 // Set config args for enforce_settings
255286 if ( ! utils . isUndefinedOrFalse ( bsConfig . run_settings . enforce_settings ) ) {
256287 markBlockStart ( 'setEnforceSettingsConfig' ) ;
@@ -310,13 +341,13 @@ module.exports = function run(args, rawArgs) {
310341 logger . debug ( "Completed polling of build status" ) ;
311342
312343 // stop the Local instance
313- await utils . stopLocalBinary ( bsConfig , bs_local , args , rawArgs , buildReportData ) ;
344+ if ( ! turboScaleSession ) await utils . stopLocalBinary ( bsConfig , bs_local , args , rawArgs , buildReportData ) ;
314345
315346 // waiting for 5 secs for upload to complete (as a safety measure)
316347 await new Promise ( resolve => setTimeout ( resolve , 5000 ) ) ;
317348
318349 // download build artifacts
319- if ( exitCode != Constants . BUILD_FAILED_EXIT_CODE ) {
350+ if ( exitCode != Constants . BUILD_FAILED_EXIT_CODE && ! turboScaleSession ) {
320351 if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
321352 logger . debug ( "Downloading build artifacts" ) ;
322353 await downloadBuildArtifacts ( bsConfig , data . build_id , args , rawArgs , buildReportData ) ;
@@ -328,7 +359,7 @@ module.exports = function run(args, rawArgs) {
328359 markBlockEnd ( 'postBuild' ) ;
329360 utils . handleSyncExit ( exitCode , data . dashboard_url ) ;
330361 } ) ;
331- } else {
362+ } else if ( ! turboScaleSession ) {
332363 let stacktraceUrl = getStackTraceUrl ( ) ;
333364 downloadBuildStacktrace ( stacktraceUrl ) . then ( ( message ) => {
334365 utils . sendUsageReport ( bsConfig , args , message , Constants . messageTypes . SUCCESS , null , buildReportData , rawArgs ) ;
@@ -344,7 +375,7 @@ module.exports = function run(args, rawArgs) {
344375 } ) ;
345376 }
346377 } ) ;
347- } else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads ) ) {
378+ } else if ( utils . nonEmptyArray ( bsConfig . run_settings . downloads && ! turboScaleSession ) ) {
348379 logger . info ( Constants . userMessages . ASYNC_DOWNLOADS . replace ( '<build-id>' , data . build_id ) ) ;
349380 }
350381
0 commit comments