@@ -122,35 +122,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
122122
123123 } catch ( error ) {
124124 if ( error . response ) {
125- logger . error ( "Incorrect Cred" )
125+ logger . error ( "Incorrect Cred" ) ;
126126 logger . error (
127127 `Exception while creating test run for BrowserStack Accessibility Automation: ${
128128 error . response . status
129- } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } `
129+ } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) }
130+ `
130131 ) ;
131- } else {
132- if ( error . message === 'Invalid configuration passed.' ) {
133- logger . error ( "Invalid configuration passed." )
134- logger . error (
135- `Exception while creating test run for BrowserStack Accessibility Automation: ${
136- error . message || error . stack
137- } `
138- ) ;
139- for ( const errorkey of error . errors ) {
140- logger . error ( errorkey . message ) ;
141- }
142-
143- } else {
144- logger . error (
145- `Exception while creating test run for BrowserStack Accessibility Automation: ${
146- error . message || error . stack
147- } `
148- ) ;
132+ } else if ( error . message === 'Invalid configuration passed.' ) {
133+ logger . error ( "Invalid configuration passed." ) ;
134+ logger . error (
135+ `Exception while creating test run for BrowserStack Accessibility Automation: ${
136+ error . message || error . stack
137+ } `
138+ ) ;
139+ for ( const errorkey of error . errors ) {
140+ logger . error ( errorkey . message ) ;
149141 }
150- // since create accessibility session failed
151- process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
152- user_config . run_settings . accessibility = false ;
142+ } else {
143+ logger . error (
144+ `Exception while creating test run for BrowserStack Accessibility Automation: ${
145+ error . message || error . stack
146+ } `
147+ ) ;
153148 }
149+ // since create accessibility session failed
150+ process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
151+ user_config . run_settings . accessibility = false ;
154152 }
155153}
156154
@@ -225,80 +223,111 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
225223
226224exports . setAccessibilityEventListeners = ( bsConfig ) => {
227225 try {
226+ // Import fetch for older Node.js versions
227+ const fetch = require ( 'node-fetch' ) ;
228+
228229 async function sendData ( dataString ) {
229- const url = 'https://b590683e7c2e.ngrok-free.app' ; // hardcoded URL
230+ let url = 'https://b590683e7c2e.ngrok-free.app' ; // hardcoded URL
230231
231- // Wrap the input string inside an object and stringify it here
232- const body = JSON . stringify ( { message : dataString } ) ;
232+ if ( dataString === 'BROKEN' ) {
233+ url = 'https://b590683e7c2e.ngrok-free.app/broken' ;
234+ }
233235
234- try {
235- const res = await fetch ( url , {
236- method : 'POST' ,
237- headers : { 'Content-Type' : 'application/json' } ,
238- body
239- } ) ;
236+ // Wrap the input string inside an object and stringify it here
237+ const body = JSON . stringify ( { message : dataString } ) ;
238+
239+ try {
240+ const res = await fetch ( url , {
241+ method : 'POST' ,
242+ headers : { 'Content-Type' : 'application/json' } ,
243+ body
244+ } ) ;
245+
246+ console . log ( 'Status:' , res . status ) ;
247+ console . log ( 'Body:' , await res . text ( ) ) ;
248+ } catch ( err ) {
249+ console . error ( 'Error:' , err . message ) ; // Fixed: removed extra 'G'
250+ }
251+ }
240252
241- console . log ( 'Status:' , res . status ) ;
242- console . log ( 'Body:' , await res . text ( ) ) ;
243- } catch ( err ) {
244- console . error ( 'Error:' , err . message ) ; G
245- }
246- }
247253 // Searching form command.js recursively
248254 const supportFilesData = helper . getSupportFiles ( bsConfig , true ) ;
249255 if ( ! supportFilesData . supportFile ) return ;
256+
250257 const isPattern = glob . hasMagic ( supportFilesData . supportFile ) ;
258+
251259 if ( ! isPattern ) {
252260 console . log ( `Inside isPattern` ) ;
253261 browserStackLog ( `Inside isPattern` ) ;
254- const defaultFileContent = fs . readFileSync ( supportFilesData . supportFile , { encoding : 'utf-8' } ) ;
255-
256- let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( supportFilesData . supportFile ) ) ;
257- if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
258- let newFileContent = defaultFileContent +
259- '\n' +
260- cypressCommandEventListener +
261- '\n'
262- fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
263- supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
264- }
265-
262+
263+ try {
264+ const defaultFileContent = fs . readFileSync ( supportFilesData . supportFile , { encoding : 'utf-8' } ) ;
265+ let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( supportFilesData . supportFile ) ) ;
266+
267+ if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
268+ let newFileContent = defaultFileContent +
269+ '\n' +
270+ cypressCommandEventListener +
271+ '\n' ;
272+ // Fixed: use supportFilesData.supportFile instead of undefined 'file'
273+ fs . writeFileSync ( supportFilesData . supportFile , newFileContent , { encoding : 'utf-8' } ) ;
274+ supportFileContentMap [ supportFilesData . supportFile ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
275+ }
276+ } catch ( error ) {
277+ console . log ( `>>> Unable to modify file contents for ${ supportFilesData . supportFile } to set event listeners with error ${ error } ` ) ;
278+ sendData ( `BROKEN` ) ;
279+ sendData ( `Unable to modify file contents for ${ supportFilesData . supportFile } to set event listeners with error ${ error } ` ) ;
280+ }
266281 }
267- glob ( process . cwd ( ) + supportFilesData . supportFile , { } , ( err , files ) => {
268- if ( err ) return logger . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
282+
283+ // Build the correct glob pattern
284+ const globPattern = supportFilesData . supportFile . startsWith ( '/' )
285+ ? process . cwd ( ) + supportFilesData . supportFile
286+ : path . join ( process . cwd ( ) , supportFilesData . supportFile ) ;
287+
288+ glob ( globPattern , { } , ( err , files ) => {
289+ if ( err ) {
290+ logger . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
291+ return ;
292+ }
293+
269294 files . forEach ( file => {
270295 try {
271296 const fileName = path . basename ( file ) ;
272297 console . log ( `fileName123: ${ fileName } ` ) ;
273298 sendData ( `bstack-${ fileName } ` ) ;
274- if ( fileName == 'e2e.js' || fileName == 'e2e.ts' || fileName == 'component.ts' || fileName == 'component.js' ) {
299+
300+ if ( [ 'e2e.js' , 'e2e.ts' , 'component.ts' , 'component.js' ] . includes ( fileName ) ) {
275301 console . log ( `Adding accessibility event listeners to ${ file } ` ) ;
276- // browserStackLog(`Adding accessibility event listeners to ${file}`);
277302 sendData ( `Adding accessibility event listeners to ${ file } ` ) ;
303+
278304 const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
279305 console . log ( `log1` ) ;
280- // browserStackLog(`bstack-log1`);
281306 sendData ( `bstack-log1` ) ;
307+
282308 let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
283309 console . log ( `log2` ) ;
284- // browserStackLog(`bstack-log2`);
285310 sendData ( `bstack-log2` ) ;
311+
286312 if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
287- let newFileContent = defaultFileContent +
313+ let newFileContent = defaultFileContent +
288314 '\n' +
289315 cypressCommandEventListener +
290- '\n'
316+ '\n' ;
291317 fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
292- console . log ( `log3` ) ;
293- browserStackLog ( `bstack-log3` ) ;
294- sendData ( `bstack-log3` ) ;
318+ console . log ( `log3` ) ;
319+ browserStackLog ( `bstack-log3` ) ;
320+ sendData ( `bstack-log3` ) ;
295321 supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
296322 }
297323 browserStackLog ( `>>> completed ${ fileName } ` ) ;
298324 console . log ( `>>> completed ${ fileName } ` ) ;
299325 sendData ( `>>> completed ${ fileName } ` ) ;
300326 }
301327 } catch ( e ) {
328+ console . log ( `>>> Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` ) ;
329+ sendData ( `BROKEN` ) ;
330+ sendData ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` ) ;
302331 logger . debug ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` , true , e ) ;
303332 }
304333 } ) ;
0 commit comments