@@ -22,7 +22,7 @@ const usageReporting = require("./usageReporting"),
2222 config = require ( "../helpers/config" ) ,
2323 pkg = require ( '../../package.json' ) ,
2424 transports = require ( './logger' ) . transports ,
25- { findGitConfig , printBuildLink , isTestObservabilitySession , isBrowserstackInfra , shouldReRunObservabilityTests } = require ( '../testObservability/helper/helper' ) ,
25+ o11yHelpers = require ( '../testObservability/helper/helper' ) ,
2626 { OBSERVABILITY_ENV_VARS , TEST_OBSERVABILITY_REPORTER } = require ( '../testObservability/helper/constants' ) ;
2727
2828const request = require ( 'request' ) ;
@@ -480,7 +480,7 @@ exports.setNodeVersion = (bsConfig, args) => {
480480// specs can be passed via command line args as a string
481481// command line args takes precedence over config
482482exports . setUserSpecs = ( bsConfig , args ) => {
483- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
483+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
484484 bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
485485 return ;
486486 }
@@ -580,8 +580,8 @@ exports.setSystemEnvs = (bsConfig) => {
580580 envKeys [ key ] = process . env [ key ] ;
581581 } ) ;
582582
583- let gitConfigPath = findGitConfig ( process . cwd ( ) ) ;
584- if ( ! isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
583+ let gitConfigPath = o11yHelpers . findGitConfig ( process . cwd ( ) ) ;
584+ if ( ! o11yHelpers . isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
585585 if ( gitConfigPath ) {
586586 const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
587587 envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -1184,8 +1184,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
11841184 syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
11851185 syncCliLogger . info ( dashboard_url ) ;
11861186 }
1187- if ( isTestObservabilitySession ( ) ) {
1188- printBuildLink ( true , exitCode ) ;
1187+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1188+ o11yHelpers . printBuildLink ( true , exitCode ) ;
11891189 } else {
11901190 process . exit ( exitCode ) ;
11911191 }
@@ -1288,7 +1288,7 @@ exports.setConfig = (bsConfig, args) => {
12881288
12891289// blindly send other passed configs with run_settings and handle at backend
12901290exports . setOtherConfigs = ( bsConfig , args ) => {
1291- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1291+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
12921292 bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
12931293 return ;
12941294 }
@@ -1453,14 +1453,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
14531453 process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
14541454}
14551455
1456+ exports . setO11yProcessHooks = ( ( ) => {
1457+ let bindData = { } ;
1458+ let handlerAdded = false ;
1459+ return ( buildId , bsConfig , bsLocal , args , buildReportData ) => {
1460+ bindData . buildId = buildId ;
1461+ bindData . bsConfig = bsConfig ;
1462+ bindData . bsLocal = bsLocal ;
1463+ bindData . args = args ;
1464+ bindData . buildReportData = buildReportData ;
1465+ if ( handlerAdded ) return ;
1466+ handlerAdded = true ;
1467+ process . on ( 'beforeExit' , processO11yExitHandler . bind ( this , bindData ) ) ;
1468+ }
1469+ } ) ( )
1470+
14561471async function processExitHandler ( exitData ) {
14571472 logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
14581473 await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
14591474 await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1460- await printBuildLink ( true ) ;
1475+ await o11yHelpers . printBuildLink ( true ) ;
14611476 process . exit ( 0 ) ;
14621477}
14631478
1479+ async function processO11yExitHandler ( exitData ) {
1480+ if ( exitData . buildId ) {
1481+ await o11yHelpers . printBuildLink ( false ) ;
1482+ } else {
1483+ await o11yHelpers . printBuildLink ( true ) ;
1484+ }
1485+ }
1486+
14641487exports . fetchZipSize = ( fileName ) => {
14651488 try {
14661489 let stats = fs . statSync ( fileName )
0 commit comments