@@ -66,7 +66,15 @@ const httpsScreenshotsKeepAliveAgent = new https.Agent({
66
66
const supportFileCleanup = ( ) => {
67
67
Object . keys ( supportFileContentMap ) . forEach ( file => {
68
68
try {
69
- fs . writeFileSync ( file , supportFileContentMap [ file ] , { encoding : 'utf-8' } ) ;
69
+ if ( typeof supportFileContentMap [ file ] === 'object' ) {
70
+ let fileOrDirpath = file ;
71
+ if ( supportFileContentMap [ file ] . deleteSupportDir ) {
72
+ fileOrDirpath = path . join ( process . cwd ( ) , 'cypress' , 'support' ) ;
73
+ }
74
+ helper . deleteSupportFileOrDir ( fileOrDirpath ) ;
75
+ } else {
76
+ fs . writeFileSync ( file , supportFileContentMap [ file ] , { encoding : 'utf-8' } ) ;
77
+ }
70
78
} catch ( e ) {
71
79
exports . debug ( `Error while replacing file content for ${ file } with it's original content with error : ${ e } ` , true , e ) ;
72
80
}
@@ -241,29 +249,33 @@ const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUI
241
249
process . env . OBSERVABILITY_LAUNCH_SDK_VERSION = OBSERVABILITY_LAUNCH_SDK_VERSION ;
242
250
}
243
251
244
- const getCypressCommandEventListener = ( ) => {
245
- return (
252
+ const getCypressCommandEventListener = ( isJS ) => {
253
+ return isJS ? (
246
254
`require('browserstack-cypress-cli/bin/testObservability/cypress');`
247
- ) ;
255
+ ) : (
256
+ `import 'browserstack-cypress-cli/bin/testObservability/cypress'`
257
+ )
248
258
}
249
259
250
- const setEventListeners = ( ) => {
260
+ exports . setEventListeners = ( bsConfig ) => {
251
261
try {
252
- const cypressCommandEventListener = getCypressCommandEventListener ( ) ;
253
- glob ( process . cwd ( ) + '/cypress/support/*.js' , { } , ( err , files ) => {
262
+ const supportFilesData = helper . getSupportFiles ( bsConfig , false ) ;
263
+ if ( ! supportFilesData . supportFile ) return ;
264
+ glob ( process . cwd ( ) + supportFilesData . supportFile , { } , ( err , files ) => {
254
265
if ( err ) return exports . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
255
266
files . forEach ( file => {
256
267
try {
257
268
if ( ! file . includes ( 'commands.js' ) ) {
258
269
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
259
270
271
+ let cypressCommandEventListener = getCypressCommandEventListener ( file . includes ( 'js' ) ) ;
260
272
if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
261
273
let newFileContent = defaultFileContent +
262
274
'\n' +
263
275
cypressCommandEventListener +
264
276
'\n'
265
277
fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
266
- supportFileContentMap [ file ] = defaultFileContent ;
278
+ supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
267
279
}
268
280
}
269
281
} catch ( e ) {
@@ -379,7 +391,6 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
379
391
exports . debug ( 'Build creation successfull!' ) ;
380
392
process . env . BS_TESTOPS_BUILD_COMPLETED = true ;
381
393
setEnvironmentVariablesForRemoteReporter ( response . data . jwt , response . data . build_hashed_id , response . data . allow_screenshots , data . observability_version . sdkVersion ) ;
382
- // setEventListeners();
383
394
if ( this . isBrowserstackInfra ( ) ) helper . setBrowserstackCypressCliDependency ( user_config ) ;
384
395
} catch ( error ) {
385
396
if ( ! error . errorType ) {
@@ -804,6 +815,7 @@ exports.resolveModule = (module) => {
804
815
} ;
805
816
806
817
const getReRunSpecs = ( rawArgs ) => {
818
+ let finalArgs = rawArgs ;
807
819
if ( this . isTestObservabilitySession ( ) && this . shouldReRunObservabilityTests ( ) ) {
808
820
let startIdx = - 1 , numEle = 0 ;
809
821
for ( let idx = 0 ; idx < rawArgs . length ; idx ++ ) {
@@ -816,10 +828,9 @@ const getReRunSpecs = (rawArgs) => {
816
828
}
817
829
}
818
830
if ( startIdx != - 1 ) rawArgs . splice ( startIdx , numEle + 1 ) ;
819
- return [ ...rawArgs , '--spec' , process . env . BROWSERSTACK_RERUN_TESTS ] ;
820
- } else {
821
- return rawArgs ;
831
+ finalArgs = [ ...rawArgs , '--spec' , process . env . BROWSERSTACK_RERUN_TESTS ] ;
822
832
}
833
+ return finalArgs . filter ( item => item !== '--disable-test-observability' && item !== '--disable-browserstack-automation' ) ;
823
834
}
824
835
825
836
const getLocalSessionReporter = ( ) => {
0 commit comments