@@ -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' ) ;
@@ -481,7 +481,7 @@ exports.setNodeVersion = (bsConfig, args) => {
481
481
// specs can be passed via command line args as a string
482
482
// command line args takes precedence over config
483
483
exports . setUserSpecs = ( bsConfig , args ) => {
484
- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
484
+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
485
485
bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
486
486
return ;
487
487
}
@@ -581,8 +581,8 @@ exports.setSystemEnvs = (bsConfig) => {
581
581
envKeys [ key ] = process . env [ key ] ;
582
582
} ) ;
583
583
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 ;
586
586
if ( gitConfigPath ) {
587
587
const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
588
588
envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -1188,8 +1188,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
1188
1188
syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
1189
1189
syncCliLogger . info ( dashboard_url ) ;
1190
1190
}
1191
- if ( isTestObservabilitySession ( ) ) {
1192
- printBuildLink ( true , exitCode ) ;
1191
+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1192
+ o11yHelpers . printBuildLink ( true , exitCode ) ;
1193
1193
} else {
1194
1194
process . exit ( exitCode ) ;
1195
1195
}
@@ -1336,7 +1336,7 @@ exports.setEnforceSettingsConfig = (bsConfig) => {
1336
1336
1337
1337
// blindly send other passed configs with run_settings and handle at backend
1338
1338
exports . setOtherConfigs = ( bsConfig , args ) => {
1339
- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1339
+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1340
1340
bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
1341
1341
return ;
1342
1342
}
@@ -1501,14 +1501,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
1501
1501
process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
1502
1502
}
1503
1503
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
+
1504
1519
async function processExitHandler ( exitData ) {
1505
1520
logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
1506
1521
await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
1507
1522
await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1508
- await printBuildLink ( true ) ;
1523
+ await o11yHelpers . printBuildLink ( true ) ;
1509
1524
process . exit ( 0 ) ;
1510
1525
}
1511
1526
1527
+ async function processO11yExitHandler ( exitData ) {
1528
+ if ( exitData . buildId ) {
1529
+ await o11yHelpers . printBuildLink ( false ) ;
1530
+ } else {
1531
+ await o11yHelpers . printBuildLink ( true ) ;
1532
+ }
1533
+ }
1534
+
1512
1535
exports . fetchZipSize = ( fileName ) => {
1513
1536
try {
1514
1537
let stats = fs . statSync ( fileName )
0 commit comments