@@ -66,7 +66,15 @@ const httpsScreenshotsKeepAliveAgent = new https.Agent({
6666const supportFileCleanup = ( ) => {
6767 Object . keys ( supportFileContentMap ) . forEach ( file => {
6868 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+ }
7078 } catch ( e ) {
7179 exports . debug ( `Error while replacing file content for ${ file } with it's original content with error : ${ e } ` , true , e ) ;
7280 }
@@ -241,29 +249,33 @@ const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUI
241249 process . env . OBSERVABILITY_LAUNCH_SDK_VERSION = OBSERVABILITY_LAUNCH_SDK_VERSION ;
242250}
243251
244- const getCypressCommandEventListener = ( ) => {
245- return (
252+ const getCypressCommandEventListener = ( isJS ) => {
253+ return isJS ? (
246254 `require('browserstack-cypress-cli/bin/testObservability/cypress');`
247- ) ;
255+ ) : (
256+ `import 'browserstack-cypress-cli/bin/testObservability/cypress'`
257+ )
248258}
249259
250- const setEventListeners = ( ) => {
260+ exports . setEventListeners = ( bsConfig ) => {
251261 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 ) => {
254265 if ( err ) return exports . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
255266 files . forEach ( file => {
256267 try {
257268 if ( ! file . includes ( 'commands.js' ) ) {
258269 const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
259270
271+ let cypressCommandEventListener = getCypressCommandEventListener ( file . includes ( 'js' ) ) ;
260272 if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
261273 let newFileContent = defaultFileContent +
262274 '\n' +
263275 cypressCommandEventListener +
264276 '\n'
265277 fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
266- supportFileContentMap [ file ] = defaultFileContent ;
278+ supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
267279 }
268280 }
269281 } catch ( e ) {
@@ -379,7 +391,6 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
379391 exports . debug ( 'Build creation successfull!' ) ;
380392 process . env . BS_TESTOPS_BUILD_COMPLETED = true ;
381393 setEnvironmentVariablesForRemoteReporter ( response . data . jwt , response . data . build_hashed_id , response . data . allow_screenshots , data . observability_version . sdkVersion ) ;
382- // setEventListeners();
383394 if ( this . isBrowserstackInfra ( ) ) helper . setBrowserstackCypressCliDependency ( user_config ) ;
384395 } catch ( error ) {
385396 if ( ! error . errorType ) {
@@ -804,6 +815,7 @@ exports.resolveModule = (module) => {
804815} ;
805816
806817const getReRunSpecs = ( rawArgs ) => {
818+ let finalArgs = rawArgs ;
807819 if ( this . isTestObservabilitySession ( ) && this . shouldReRunObservabilityTests ( ) ) {
808820 let startIdx = - 1 , numEle = 0 ;
809821 for ( let idx = 0 ; idx < rawArgs . length ; idx ++ ) {
@@ -816,10 +828,9 @@ const getReRunSpecs = (rawArgs) => {
816828 }
817829 }
818830 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 ] ;
822832 }
833+ return finalArgs . filter ( item => item !== '--disable-test-observability' && item !== '--disable-browserstack-automation' ) ;
823834}
824835
825836const getLocalSessionReporter = ( ) => {
0 commit comments