@@ -22,7 +22,7 @@ const usageReporting = require("./usageReporting"),
22
22
config = require ( "../helpers/config" ) ,
23
23
pkg = require ( '../../package.json' ) ,
24
24
transports = require ( './logger' ) . transports ,
25
- { findGitConfig , printBuildLink , isTestObservabilitySession , isBrowserstackInfra , shouldReRunObservabilityTests } = require ( '../testObservability/helper/helper' ) ,
25
+ o11yHelpers = require ( '../testObservability/helper/helper' ) ,
26
26
{ OBSERVABILITY_ENV_VARS , TEST_OBSERVABILITY_REPORTER } = require ( '../testObservability/helper/constants' ) ;
27
27
28
28
const request = require ( 'request' ) ;
@@ -480,7 +480,7 @@ exports.setNodeVersion = (bsConfig, args) => {
480
480
// specs can be passed via command line args as a string
481
481
// command line args takes precedence over config
482
482
exports . setUserSpecs = ( bsConfig , args ) => {
483
- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
483
+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
484
484
bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
485
485
return ;
486
486
}
@@ -580,8 +580,8 @@ exports.setSystemEnvs = (bsConfig) => {
580
580
envKeys [ key ] = process . env [ key ] ;
581
581
} ) ;
582
582
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 ;
585
585
if ( gitConfigPath ) {
586
586
const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
587
587
envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -1184,8 +1184,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
1184
1184
syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
1185
1185
syncCliLogger . info ( dashboard_url ) ;
1186
1186
}
1187
- if ( isTestObservabilitySession ( ) ) {
1188
- printBuildLink ( true , exitCode ) ;
1187
+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1188
+ o11yHelpers . printBuildLink ( true , exitCode ) ;
1189
1189
} else {
1190
1190
process . exit ( exitCode ) ;
1191
1191
}
@@ -1288,7 +1288,7 @@ exports.setConfig = (bsConfig, args) => {
1288
1288
1289
1289
// blindly send other passed configs with run_settings and handle at backend
1290
1290
exports . setOtherConfigs = ( bsConfig , args ) => {
1291
- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1291
+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1292
1292
bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
1293
1293
return ;
1294
1294
}
@@ -1453,14 +1453,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
1453
1453
process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
1454
1454
}
1455
1455
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
+
1456
1471
async function processExitHandler ( exitData ) {
1457
1472
logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
1458
1473
await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
1459
1474
await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1460
- await printBuildLink ( true ) ;
1475
+ await o11yHelpers . printBuildLink ( true ) ;
1461
1476
process . exit ( 0 ) ;
1462
1477
}
1463
1478
1479
+ async function processO11yExitHandler ( exitData ) {
1480
+ if ( exitData . buildId ) {
1481
+ await o11yHelpers . printBuildLink ( false ) ;
1482
+ } else {
1483
+ await o11yHelpers . printBuildLink ( true ) ;
1484
+ }
1485
+ }
1486
+
1464
1487
exports . fetchZipSize = ( fileName ) => {
1465
1488
try {
1466
1489
let stats = fs . statSync ( fileName )
0 commit comments