@@ -11,7 +11,6 @@ const getRepoInfo = require('git-repo-info');
11
11
const gitconfig = require ( 'gitconfiglocal' ) ;
12
12
const { spawn, execSync } = require ( 'child_process' ) ;
13
13
const glob = require ( 'glob' ) ;
14
- const platformDetect = require ( 'platform-detect' ) ;
15
14
16
15
const pGitconfig = promisify ( gitconfig ) ;
17
16
@@ -24,6 +23,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
24
23
25
24
const { name, version } = require ( '../../../package.json' ) ;
26
25
26
+ const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../../helpers/constants' ) ;
27
27
const { consoleHolder, API_URL } = require ( './constants' ) ;
28
28
exports . pending_test_uploads = {
29
29
count : 0
@@ -382,7 +382,7 @@ const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUI
382
382
383
383
const getCypressCommandEventListener = ( ) => {
384
384
return (
385
- `require('browserstack-cypress-cli/bin/testObservability/cypress/cypressEventListeners ');`
385
+ `require('browserstack-cypress-cli/bin/testObservability/cypress');`
386
386
) ;
387
387
}
388
388
@@ -427,7 +427,7 @@ const getBuildDetails = (bsConfig) => {
427
427
if ( isTestObservabilityOptionsPresent ) {
428
428
buildName = buildName || bsConfig [ "testObservabilityOptions" ] [ "buildName" ] ;
429
429
projectName = projectName || bsConfig [ "testObservabilityOptions" ] [ "projectName" ] ;
430
- buildTags = [ ...buildTags , ...bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ] ;
430
+ if ( ! utils . isUndefined ( bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ) ) buildTags = [ ...buildTags , ...bsConfig [ "testObservabilityOptions" ] [ "buildTag" ] ] ;
431
431
buildDescription = buildDescription || bsConfig [ "testObservabilityOptions" ] [ "buildDescription" ] ;
432
432
}
433
433
@@ -460,8 +460,8 @@ const setBrowserstackCypressCliDependency = (bsConfig) => {
460
460
}
461
461
462
462
const 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 ;
465
465
return cypressConfigFile ;
466
466
}
467
467
@@ -560,27 +560,26 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
560
560
setEventListeners ( ) ;
561
561
if ( this . isBrowserstackInfra ( ) ) setBrowserstackCypressCliDependency ( user_config ) ;
562
562
} 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
+ }
565
569
} 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 ;
572
571
switch ( errorType ) {
573
572
case 'ERROR_INVALID_CREDENTIALS' :
574
- logger . error ( errorMessage ) ;
573
+ logger . error ( message ) ;
575
574
break ;
576
575
case 'ERROR_ACCESS_DENIED' :
577
- logger . info ( errorMessage ) ;
576
+ logger . info ( message ) ;
578
577
break ;
579
578
case 'ERROR_SDK_DEPRECATED' :
580
- logger . error ( errorMessage ) ;
579
+ logger . error ( message ) ;
581
580
break ;
582
581
default :
583
- logger . error ( errorMessage ) ;
582
+ logger . error ( message ) ;
584
583
}
585
584
}
586
585
@@ -626,6 +625,7 @@ exports.mapTestHooks = (test) => {
626
625
testHook . hookAnalyticsId = uuidv4 ( ) ;
627
626
delete testHook . markedStatus ;
628
627
}
628
+ testHook [ 'test_run_id' ] = testHook [ 'test_run_id' ] || test . testAnalyticsId ;
629
629
} )
630
630
} ) ;
631
631
exports . mapTestHooks ( test . parent ) ;
@@ -740,17 +740,23 @@ exports.uploadEventData = async (eventData, run=0) => {
740
740
}
741
741
}
742
742
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
+
743
748
exports . setTestObservabilityFlags = ( bsConfig ) => {
744
749
/* testObservability */
745
750
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" ) ;
748
753
if ( process . argv . includes ( '--disable-test-observability' ) ) isTestObservabilitySession = false ;
754
+ isTestObservabilitySession = isTestObservabilitySession && this . isTestObservabilitySupportedCypressVersion ( bsConfig . run_settings . cypress_config_file ) ;
749
755
750
756
/* browserstackAutomation */
751
757
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" ) ;
754
760
if ( process . argv . includes ( '--disable-browserstack-automation' ) ) isBrowserstackInfra = false ;
755
761
756
762
process . env . BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession ;
@@ -845,13 +851,9 @@ exports.getHookSkippedTests = (suite) => {
845
851
}
846
852
847
853
const 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'
855
857
return 'Unknown'
856
858
}
857
859
@@ -946,8 +948,19 @@ const getLocalSessionReporter = () => {
946
948
}
947
949
}
948
950
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
+
949
961
exports . runCypressTestsLocally = ( bsConfig , args , rawArgs ) => {
950
962
try {
963
+ rawArgs = cleanupTestObservabilityFlags ( rawArgs ) ;
951
964
logger . info ( `Running npx cypress run ${ getReRunSpecs ( rawArgs . slice ( 1 ) ) . join ( ' ' ) } ${ getLocalSessionReporter ( ) . join ( ' ' ) } ` ) ;
952
965
const cypressProcess = spawn (
953
966
'npx' ,
0 commit comments