@@ -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' ) ;
@@ -481,7 +481,7 @@ exports.setNodeVersion = (bsConfig, args) => {
481481// specs can be passed via command line args as a string
482482// command line args takes precedence over config
483483exports . setUserSpecs = ( bsConfig , args ) => {
484- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
484+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
485485 bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
486486 return ;
487487 }
@@ -581,8 +581,8 @@ exports.setSystemEnvs = (bsConfig) => {
581581 envKeys [ key ] = process . env [ key ] ;
582582 } ) ;
583583
584- let gitConfigPath = findGitConfig ( process . cwd ( ) ) ;
585- if ( ! isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
584+ let gitConfigPath = o11yHelpers . findGitConfig ( process . cwd ( ) ) ;
585+ if ( ! o11yHelpers . isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
586586 if ( gitConfigPath ) {
587587 const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
588588 envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -1188,8 +1188,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
11881188 syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
11891189 syncCliLogger . info ( dashboard_url ) ;
11901190 }
1191- if ( isTestObservabilitySession ( ) ) {
1192- printBuildLink ( true , exitCode ) ;
1191+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1192+ o11yHelpers . printBuildLink ( true , exitCode ) ;
11931193 } else {
11941194 process . exit ( exitCode ) ;
11951195 }
@@ -1336,7 +1336,7 @@ exports.setEnforceSettingsConfig = (bsConfig) => {
13361336
13371337// blindly send other passed configs with run_settings and handle at backend
13381338exports . setOtherConfigs = ( bsConfig , args ) => {
1339- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1339+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
13401340 bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
13411341 return ;
13421342 }
@@ -1501,14 +1501,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
15011501 process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
15021502}
15031503
1504+ exports . setO11yProcessHooks = ( ( ) => {
1505+ let bindData = { } ;
1506+ let handlerAdded = false ;
1507+ return ( buildId , bsConfig , bsLocal , args , buildReportData ) => {
1508+ bindData . buildId = buildId ;
1509+ bindData . bsConfig = bsConfig ;
1510+ bindData . bsLocal = bsLocal ;
1511+ bindData . args = args ;
1512+ bindData . buildReportData = buildReportData ;
1513+ if ( handlerAdded ) return ;
1514+ handlerAdded = true ;
1515+ process . on ( 'beforeExit' , processO11yExitHandler . bind ( this , bindData ) ) ;
1516+ }
1517+ } ) ( )
1518+
15041519async function processExitHandler ( exitData ) {
15051520 logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
15061521 await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
15071522 await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1508- await printBuildLink ( true ) ;
1523+ await o11yHelpers . printBuildLink ( true ) ;
15091524 process . exit ( 0 ) ;
15101525}
15111526
1527+ async function processO11yExitHandler ( exitData ) {
1528+ if ( exitData . buildId ) {
1529+ await o11yHelpers . printBuildLink ( false ) ;
1530+ } else {
1531+ await o11yHelpers . printBuildLink ( true ) ;
1532+ }
1533+ }
1534+
15121535exports . fetchZipSize = ( fileName ) => {
15131536 try {
15141537 let stats = fs . statSync ( fileName )
0 commit comments