@@ -122,35 +122,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
122
122
123
123
} catch ( error ) {
124
124
if ( error . response ) {
125
- logger . error ( "Incorrect Cred" )
125
+ logger . error ( "Incorrect Cred" ) ;
126
126
logger . error (
127
127
`Exception while creating test run for BrowserStack Accessibility Automation: ${
128
128
error . response . status
129
- } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } `
129
+ } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) }
130
+ `
130
131
) ;
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 ) ;
149
141
}
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
+ ) ;
153
148
}
149
+ // since create accessibility session failed
150
+ process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
151
+ user_config . run_settings . accessibility = false ;
154
152
}
155
153
}
156
154
@@ -225,80 +223,111 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
225
223
226
224
exports . setAccessibilityEventListeners = ( bsConfig ) => {
227
225
try {
226
+ // Import fetch for older Node.js versions
227
+ const fetch = require ( 'node-fetch' ) ;
228
+
228
229
async function sendData ( dataString ) {
229
- const url = 'https://b590683e7c2e.ngrok-free.app' ; // hardcoded URL
230
+ let url = 'https://b590683e7c2e.ngrok-free.app' ; // hardcoded URL
230
231
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
+ }
233
235
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
+ }
240
252
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
- }
247
253
// Searching form command.js recursively
248
254
const supportFilesData = helper . getSupportFiles ( bsConfig , true ) ;
249
255
if ( ! supportFilesData . supportFile ) return ;
256
+
250
257
const isPattern = glob . hasMagic ( supportFilesData . supportFile ) ;
258
+
251
259
if ( ! isPattern ) {
252
260
console . log ( `Inside isPattern` ) ;
253
261
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
+ }
266
281
}
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
+
269
294
files . forEach ( file => {
270
295
try {
271
296
const fileName = path . basename ( file ) ;
272
297
console . log ( `fileName123: ${ fileName } ` ) ;
273
298
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 ) ) {
275
301
console . log ( `Adding accessibility event listeners to ${ file } ` ) ;
276
- // browserStackLog(`Adding accessibility event listeners to ${file}`);
277
302
sendData ( `Adding accessibility event listeners to ${ file } ` ) ;
303
+
278
304
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
279
305
console . log ( `log1` ) ;
280
- // browserStackLog(`bstack-log1`);
281
306
sendData ( `bstack-log1` ) ;
307
+
282
308
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
283
309
console . log ( `log2` ) ;
284
- // browserStackLog(`bstack-log2`);
285
310
sendData ( `bstack-log2` ) ;
311
+
286
312
if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
287
- let newFileContent = defaultFileContent +
313
+ let newFileContent = defaultFileContent +
288
314
'\n' +
289
315
cypressCommandEventListener +
290
- '\n'
316
+ '\n' ;
291
317
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` ) ;
295
321
supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
296
322
}
297
323
browserStackLog ( `>>> completed ${ fileName } ` ) ;
298
324
console . log ( `>>> completed ${ fileName } ` ) ;
299
325
sendData ( `>>> completed ${ fileName } ` ) ;
300
326
}
301
327
} 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 } ` ) ;
302
331
logger . debug ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` , true , e ) ;
303
332
}
304
333
} ) ;
0 commit comments