@@ -12,15 +12,6 @@ const { consoleHolder } = require("../testObservability/helper/constants");
12
12
const supportFileContentMap = { }
13
13
const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
14
14
15
- const browserStackLog = ( message ) => {
16
- // if (!Cypress.env('BROWSERSTACK_LOGS')) return;
17
- if ( typeof cy === 'undefined' ) {
18
- console . warn ( 'Cypress is not defined. Ensure that this code is running in a Cypress environment.' ) ;
19
- } else {
20
- cy . task ( 'browserstack_log' , message ) ;
21
- }
22
- }
23
-
24
15
exports . checkAccessibilityPlatform = ( user_config ) => {
25
16
let accessibility = false ;
26
17
try {
@@ -227,78 +218,29 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
227
218
228
219
exports . setAccessibilityEventListeners = ( bsConfig ) => {
229
220
try {
230
- // Import fetch for older Node.js versions
231
- const fetch = require ( 'node-fetch' ) ;
232
-
233
- async function sendData ( dataString ) {
234
- let url = 'https://b590683e7c2e.ngrok-free.app' ; // hardcoded URL
235
-
236
- if ( dataString === 'BROKEN' ) {
237
- url = 'https://b590683e7c2e.ngrok-free.app/broken' ;
238
- }
239
-
240
- // Wrap the input string inside an object and stringify it here
241
- const body = JSON . stringify ( { message : dataString } ) ;
242
-
243
- try {
244
- const res = await fetch ( url , {
245
- method : 'POST' ,
246
- headers : { 'Content-Type' : 'application/json' } ,
247
- body
248
- } ) ;
249
221
250
- console . log ( 'Status:' , res . status ) ;
251
- console . log ( 'Body:' , await res . text ( ) ) ;
252
- } catch ( err ) {
253
- console . error ( 'Error:' , err . message ) ; // Fixed: removed extra 'G'
254
- }
255
- }
256
-
257
- // Searching form command.js recursively
258
222
const supportFilesData = helper . getSupportFiles ( bsConfig , true ) ;
259
223
if ( ! supportFilesData . supportFile ) return ;
260
224
261
225
const isPattern = glob . hasMagic ( supportFilesData . supportFile ) ;
262
226
263
227
if ( ! isPattern ) {
264
228
console . log ( `Inside isPattern` ) ;
265
- browserStackLog ( `Inside isPattern` ) ;
266
-
267
229
try {
268
230
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
269
- console . log ( `log1` ) ;
270
- sendData ( `bstack-log1` ) ;
271
-
272
231
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
273
- console . log ( `log2` ) ;
274
- sendData ( `bstack-log2` ) ;
275
-
276
- // Add debugging to understand why the condition fails
277
232
const alreadyIncludes = defaultFileContent . includes ( cypressCommandEventListener ) ;
278
- console . log ( `File ${ file } already includes accessibility listener: ${ alreadyIncludes } ` ) ;
279
- console . log ( `Looking for: ${ cypressCommandEventListener } ` ) ;
280
- console . log ( `In content (first 500 chars): ${ defaultFileContent . substring ( 0 , 500 ) } ` ) ;
281
- sendData ( `bstack-already-includes-${ alreadyIncludes } ` ) ;
282
-
283
233
if ( ! alreadyIncludes ) {
284
234
let newFileContent = defaultFileContent +
285
235
'\n' +
286
236
cypressCommandEventListener +
287
237
'\n' ;
288
238
fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
289
- console . log ( `log3` ) ;
290
- browserStackLog ( `bstack-log3` ) ;
291
- sendData ( `bstack-log3` ) ;
292
239
supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
293
- } else {
294
- console . log ( `Skipping ${ file } - accessibility listener already present` ) ;
295
- sendData ( `bstack-skipped-${ path . basename ( file ) } ` ) ;
296
240
}
297
- } catch ( error ) {
298
- console . log ( `>>> Unable to modify file contents for ${ supportFilesData . supportFile } to set event listeners with error ${ error } ` ) ;
299
- sendData ( `BROKEN` ) ;
300
- sendData ( `Unable to modify file contents for ${ supportFilesData . supportFile } to set event listeners with error ${ error } ` ) ;
301
- }
241
+ } catch ( e ) {
242
+ logger . debug ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` , true , e ) ;
243
+ }
302
244
}
303
245
304
246
// Build the correct glob pattern
@@ -315,40 +257,21 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
315
257
files . forEach ( file => {
316
258
try {
317
259
const fileName = path . basename ( file ) ;
318
- console . log ( `fileName123: ${ fileName } ` ) ;
319
- sendData ( `bstack-${ fileName } ` ) ;
320
-
321
260
if ( [ 'e2e.js' , 'e2e.ts' , 'component.ts' , 'component.js' ] . includes ( fileName ) && ! file . includes ( 'node_modules' ) ) {
322
- console . log ( `Adding accessibility event listeners to ${ file } ` ) ;
323
- sendData ( `Adding accessibility event listeners to ${ file } ` ) ;
324
-
261
+
325
262
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
326
- console . log ( `log1` ) ;
327
- sendData ( `bstack-log1` ) ;
328
-
329
263
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
330
- console . log ( `log2` ) ;
331
- sendData ( `bstack-log2` ) ;
332
-
264
+
333
265
if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
334
266
let newFileContent = defaultFileContent +
335
267
'\n' +
336
268
cypressCommandEventListener +
337
269
'\n' ;
338
270
fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
339
- console . log ( `log3` ) ;
340
- browserStackLog ( `bstack-log3` ) ;
341
- sendData ( `bstack-log3` ) ;
342
271
supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
343
272
}
344
- browserStackLog ( `>>> completed ${ fileName } ` ) ;
345
- console . log ( `>>> completed ${ fileName } ` ) ;
346
- sendData ( `>>> completed ${ fileName } ` ) ;
347
273
}
348
274
} catch ( e ) {
349
- console . log ( `>>> Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` ) ;
350
- sendData ( `BROKEN` ) ;
351
- sendData ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` ) ;
352
275
logger . debug ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` , true , e ) ;
353
276
}
354
277
} ) ;
0 commit comments