@@ -24,7 +24,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
24
24
const { name, version } = require ( '../../../package.json' ) ;
25
25
26
26
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../../helpers/constants' ) ;
27
- const { consoleHolder, API_URL } = require ( './constants' ) ;
27
+ const { consoleHolder, API_URL , TEST_OBSERVABILITY_REPORTER } = require ( './constants' ) ;
28
28
exports . pending_test_uploads = {
29
29
count : 0
30
30
} ;
@@ -777,56 +777,48 @@ exports.shouldReRunObservabilityTests = () => {
777
777
return ( process . env . BROWSERSTACK_RERUN_TESTS && process . env . BROWSERSTACK_RERUN_TESTS !== "null" ) ? true : false
778
778
}
779
779
780
- exports . stopBuildUpstream = async ( buildStartWaitRun = 0 , testUploadWaitRun = 0 , forceStop = false ) => {
781
- if ( process . env . BS_TESTOPS_BUILD_COMPLETED !== "false" && ! forceStop && exports . pending_test_uploads . count && testUploadWaitRun < 5 ) {
782
- exports . debug ( `stopBuildUpstream event : retry count ${ testUploadWaitRun + 1 } due to pending event uploads ${ exports . pending_test_uploads . count } ` ) ;
783
- setTimeout ( function ( ) { exports . stopBuildUpstream ( buildStartWaitRun , testUploadWaitRun + 1 , false ) } , 5000 ) ;
784
- } else {
785
- if ( process . env . BS_TESTOPS_BUILD_COMPLETED === "true" ) {
786
- if ( process . env . BS_TESTOPS_JWT == "null" || process . env . BS_TESTOPS_BUILD_HASHED_ID == "null" ) {
787
- exports . debug ( 'EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : Missing authentication token' ) ;
788
- return {
789
- status : 'error' ,
790
- message : 'Token/buildID is undefined, build creation might have failed'
791
- } ;
792
- } else {
793
- const data = {
794
- 'stop_time' : ( new Date ( ) ) . toISOString ( )
795
- } ;
796
- const config = {
797
- headers : {
798
- 'Authorization' : `Bearer ${ process . env . BS_TESTOPS_JWT } ` ,
799
- 'Content-Type' : 'application/json' ,
800
- 'X-BSTACK-TESTOPS' : 'true'
801
- }
802
- } ;
803
-
804
- try {
805
- const response = await nodeRequest ( 'PUT' , `api/v1/builds/${ process . env . BS_TESTOPS_BUILD_HASHED_ID } /stop` , data , config ) ;
806
- if ( response . data && response . data . error ) {
807
- throw ( { message : response . data . error } ) ;
808
- } else {
809
- exports . debug ( `stopBuildUpstream buildStartWaitRun[${ buildStartWaitRun } ] testUploadWaitRun[${ testUploadWaitRun } ] event successfull!` )
810
- return {
811
- status : 'success' ,
812
- message : ''
813
- } ;
814
- }
815
- } catch ( error ) {
816
- if ( error . response ) {
817
- exports . debug ( `EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
818
- } else {
819
- exports . debug ( `EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${ error . message || error } ` , true , error ) ;
820
- }
780
+ exports . stopBuildUpstream = async ( ) => {
781
+ if ( process . env . BS_TESTOPS_BUILD_COMPLETED === "true" ) {
782
+ if ( process . env . BS_TESTOPS_JWT == "null" || process . env . BS_TESTOPS_BUILD_HASHED_ID == "null" ) {
783
+ exports . debug ( 'EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : Missing authentication token' ) ;
784
+ return {
785
+ status : 'error' ,
786
+ message : 'Token/buildID is undefined, build creation might have failed'
787
+ } ;
788
+ } else {
789
+ const data = {
790
+ 'stop_time' : ( new Date ( ) ) . toISOString ( )
791
+ } ;
792
+ const config = {
793
+ headers : {
794
+ 'Authorization' : `Bearer ${ process . env . BS_TESTOPS_JWT } ` ,
795
+ 'Content-Type' : 'application/json' ,
796
+ 'X-BSTACK-TESTOPS' : 'true'
797
+ }
798
+ } ;
799
+
800
+ try {
801
+ const response = await nodeRequest ( 'PUT' , `api/v1/builds/${ process . env . BS_TESTOPS_BUILD_HASHED_ID } /stop` , data , config ) ;
802
+ if ( response . data && response . data . error ) {
803
+ throw ( { message : response . data . error } ) ;
804
+ } else {
805
+ exports . debug ( `stopBuildUpstream event successfull!` )
821
806
return {
822
- status : 'error ' ,
823
- message : error . message || error . response ? ` ${ error . response . status } : ${ error . response . statusText } ` : error
807
+ status : 'success ' ,
808
+ message : ''
824
809
} ;
825
810
}
811
+ } catch ( error ) {
812
+ if ( error . response ) {
813
+ exports . debug ( `EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
814
+ } else {
815
+ exports . debug ( `EXCEPTION IN stopBuildUpstream REQUEST TO TEST OBSERVABILITY : ${ error . message || error } ` , true , error ) ;
816
+ }
817
+ return {
818
+ status : 'error' ,
819
+ message : error . message || error . response ? `${ error . response . status } :${ error . response . statusText } ` : error
820
+ } ;
826
821
}
827
- } else if ( process . env . BS_TESTOPS_BUILD_COMPLETED !== "false" ) {
828
- /* forceStop = true since we won't wait for pendingUploads trigerred post stop flow */
829
- setTimeout ( function ( ) { exports . stopBuildUpstream ( buildStartWaitRun + 1 , testUploadWaitRun , true ) } , 1000 ) ;
830
822
}
831
823
}
832
824
}
@@ -942,7 +934,7 @@ const getReRunSpecs = (rawArgs) => {
942
934
943
935
const getLocalSessionReporter = ( ) => {
944
936
if ( this . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
945
- return [ '--reporter' , 'browserstack-cypress-cli/bin/testObservability/reporter' ] ;
937
+ return [ '--reporter' , TEST_OBSERVABILITY_REPORTER ] ;
946
938
} else {
947
939
return [ ] ;
948
940
}
0 commit comments