@@ -11,7 +11,6 @@ const getRepoInfo = require('git-repo-info');
1111const gitconfig = require ( 'gitconfiglocal' ) ;
1212const { spawn, execSync } = require ( 'child_process' ) ;
1313const glob = require ( 'glob' ) ;
14- const platformDetect = require ( 'platform-detect' ) ;
1514
1615const pGitconfig = promisify ( gitconfig ) ;
1716
@@ -24,6 +23,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
2423
2524const { name, version } = require ( '../../../package.json' ) ;
2625
26+ const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../../helpers/constants' ) ;
2727const { consoleHolder, API_URL } = require ( './constants' ) ;
2828exports . pending_test_uploads = {
2929 count : 0
@@ -382,7 +382,7 @@ const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUI
382382
383383const getCypressCommandEventListener = ( ) => {
384384 return (
385- `require('browserstack-cypress-cli/bin/testObservability/cypress/cypressEventListeners ');`
385+ `require('browserstack-cypress-cli/bin/testObservability/cypress');`
386386 ) ;
387387}
388388
@@ -427,7 +427,7 @@ const getBuildDetails = (bsConfig) => {
427427 if ( isTestObservabilityOptionsPresent ) {
428428 buildName = buildName || bsConfig [ "testObservabilityOptions" ] [ "buildName" ] ;
429429 projectName = projectName || bsConfig [ "testObservabilityOptions" ] [ "projectName" ] ;
430- buildTags = [ ...buildTags , ...bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ] ;
430+ if ( ! utils . isUndefined ( bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ) ) buildTags = [ ...buildTags , ...bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ] ;
431431 buildDescription = buildDescription || bsConfig [ "testObservabilityOptions" ] [ "buildDescription" ] ;
432432 }
433433
@@ -460,8 +460,8 @@ const setBrowserstackCypressCliDependency = (bsConfig) => {
460460}
461461
462462const getCypressConfigFileContent = ( bsConfig , cypressConfigPath ) => {
463- const cypressConfigFile = require ( path . resolve ( bsConfig ? bsConfig . run_settings . cypressConfigFilePath : cypressConfigPath ) ) ;
464- if ( bsConfig ) process . env . OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH = bsConfig . run_settings . cypressConfigFilePath ;
463+ const cypressConfigFile = require ( path . resolve ( bsConfig ? bsConfig . run_settings . cypress_config_file : cypressConfigPath ) ) ;
464+ if ( bsConfig ) process . env . OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH = bsConfig . run_settings . cypress_config_file ;
465465 return cypressConfigFile ;
466466}
467467
@@ -560,27 +560,26 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
560560 setEventListeners ( ) ;
561561 if ( this . isBrowserstackInfra ( ) ) setBrowserstackCypressCliDependency ( user_config ) ;
562562 } catch ( error ) {
563- if ( error . response ) {
564- exports . debug ( `EXCEPTION IN BUILD START EVENT : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
563+ if ( ! error . errorType ) {
564+ if ( error . response ) {
565+ exports . debug ( `EXCEPTION IN BUILD START EVENT : ${ error . response . status } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } ` , true , error ) ;
566+ } else {
567+ exports . debug ( `EXCEPTION IN BUILD START EVENT : ${ error . message || error } ` , true , error ) ;
568+ }
565569 } else {
566- exports . debug ( `EXCEPTION IN BUILD START EVENT : ${ error . message || error } ` , true , error ) ;
567- }
568-
569- if ( error . response ) {
570- const errorMessageJson = error . response . body ? JSON . parse ( error . response . body . toString ( ) ) : null
571- const errorMessage = errorMessageJson ? errorMessageJson . message : null , errorType = errorMessageJson ? errorMessageJson . errorType : null
570+ const { errorType, message } = error ;
572571 switch ( errorType ) {
573572 case 'ERROR_INVALID_CREDENTIALS' :
574- logger . error ( errorMessage ) ;
573+ logger . error ( message ) ;
575574 break ;
576575 case 'ERROR_ACCESS_DENIED' :
577- logger . info ( errorMessage ) ;
576+ logger . info ( message ) ;
578577 break ;
579578 case 'ERROR_SDK_DEPRECATED' :
580- logger . error ( errorMessage ) ;
579+ logger . error ( message ) ;
581580 break ;
582581 default :
583- logger . error ( errorMessage ) ;
582+ logger . error ( message ) ;
584583 }
585584 }
586585
@@ -626,6 +625,7 @@ exports.mapTestHooks = (test) => {
626625 testHook . hookAnalyticsId = uuidv4 ( ) ;
627626 delete testHook . markedStatus ;
628627 }
628+ testHook [ 'test_run_id' ] = testHook [ 'test_run_id' ] || test . testAnalyticsId ;
629629 } )
630630 } ) ;
631631 exports . mapTestHooks ( test . parent ) ;
@@ -740,17 +740,23 @@ exports.uploadEventData = async (eventData, run=0) => {
740740 }
741741}
742742
743+ exports . isTestObservabilitySupportedCypressVersion = ( cypress_config_filename ) => {
744+ const extension = cypress_config_filename . split ( '.' ) . pop ( ) ;
745+ return CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS . includes ( extension ) ;
746+ }
747+
743748exports . setTestObservabilityFlags = ( bsConfig ) => {
744749 /* testObservability */
745750 let isTestObservabilitySession = true ;
746- if ( bsConfig [ "testObservability" ] ) isTestObservabilitySession = ( bsConfig [ "testObservability" ] == true ) ;
747- if ( process . env . BROWSERSTACK_TEST_OBSERVABILITY ) isTestObservabilitySession = ( process . env . BROWSERSTACK_TEST_OBSERVABILITY == "true" ) ;
751+ if ( ! utils . isUndefined ( bsConfig [ "testObservability" ] ) ) isTestObservabilitySession = ( bsConfig [ "testObservability" ] == true ) ;
752+ if ( ! utils . isUndefined ( process . env . BROWSERSTACK_TEST_OBSERVABILITY ) ) isTestObservabilitySession = ( process . env . BROWSERSTACK_TEST_OBSERVABILITY == "true" ) ;
748753 if ( process . argv . includes ( '--disable-test-observability' ) ) isTestObservabilitySession = false ;
754+ isTestObservabilitySession = isTestObservabilitySession && this . isTestObservabilitySupportedCypressVersion ( bsConfig . run_settings . cypress_config_file ) ;
749755
750756 /* browserstackAutomation */
751757 let isBrowserstackInfra = true ;
752- if ( bsConfig [ "browserstackAutomation" ] ) isBrowserstackInfra = ( bsConfig [ "browserstackAutomation" ] == true ) ;
753- if ( process . env . BROWSERSTACK_AUTOMATION ) isBrowserstackInfra = ( process . env . BROWSERSTACK_AUTOMATION == "true" ) ;
758+ if ( ! utils . isUndefined ( bsConfig [ "browserstackAutomation" ] ) ) isBrowserstackInfra = ( bsConfig [ "browserstackAutomation" ] == true ) ;
759+ if ( ! utils . isUndefined ( process . env . BROWSERSTACK_AUTOMATION ) ) isBrowserstackInfra = ( process . env . BROWSERSTACK_AUTOMATION == "true" ) ;
754760 if ( process . argv . includes ( '--disable-browserstack-automation' ) ) isBrowserstackInfra = false ;
755761
756762 process . env . BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession ;
@@ -845,13 +851,9 @@ exports.getHookSkippedTests = (suite) => {
845851}
846852
847853const getPlatformName = ( ) => {
848- if ( platformDetect . windows ) return 'Windows'
849- if ( platformDetect . macos ) return 'OS X'
850- if ( platformDetect . android ) return 'Android'
851- if ( platformDetect . ios ) return 'IOS'
852- if ( platformDetect . linux ) return 'Linux'
853- if ( platformDetect . tizen ) return 'Tizen'
854- if ( platformDetect . chromeos ) return 'Chrome OS'
854+ if ( process . platform === 'win32' ) return 'Windows'
855+ if ( process . platform === 'darwin' ) return 'OS X'
856+ if ( process . platform === "linux" ) return 'Linux'
855857 return 'Unknown'
856858}
857859
@@ -946,8 +948,19 @@ const getLocalSessionReporter = () => {
946948 }
947949}
948950
951+ const cleanupTestObservabilityFlags = ( rawArgs ) => {
952+ const newRawArgs = [ ] ;
953+ for ( let idx = 0 ; idx < rawArgs . length ; idx ++ ) {
954+ if ( ! [ '--disable-browserstack-automation' , '--disable-test-observability' ] . includes ( rawArgs [ idx ] ) ) {
955+ newRawArgs . push ( rawArgs [ idx ] ) ;
956+ }
957+ }
958+ return newRawArgs ;
959+ }
960+
949961exports . runCypressTestsLocally = ( bsConfig , args , rawArgs ) => {
950962 try {
963+ rawArgs = cleanupTestObservabilityFlags ( rawArgs ) ;
951964 logger . info ( `Running npx cypress run ${ getReRunSpecs ( rawArgs . slice ( 1 ) ) . join ( ' ' ) } ${ getLocalSessionReporter ( ) . join ( ' ' ) } ` ) ;
952965 const cypressProcess = spawn (
953966 'npx' ,
0 commit comments