@@ -233,12 +233,33 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
233233 // Searching form command.js recursively
234234 const supportFilesData = helper . getSupportFiles ( bsConfig , true ) ;
235235 if ( ! supportFilesData . supportFile ) return ;
236+ const isPattern = glob . hasMagic ( supportFilesData . supportFile ) ;
237+ if ( ! isPattern ) {
238+ console . debug ( `Inside isPattern` ) ;
239+ logger . debug ( `Inside isPattern` ) ;
240+ const defaultFileContent = fs . readFileSync ( supportFilesData . supportFile , { encoding : 'utf-8' } ) ;
241+
242+ let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( supportFilesData . supportFile ) ) ;
243+ if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
244+ let newFileContent = defaultFileContent +
245+ '\n' +
246+ cypressCommandEventListener +
247+ '\n'
248+ fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
249+ supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
250+ }
251+
252+ }
236253 glob ( process . cwd ( ) + supportFilesData . supportFile , { } , ( err , files ) => {
237254 if ( err ) return logger . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
238255 files . forEach ( file => {
239256 try {
240257 const fileName = path . basename ( file ) ;
241- if ( ( fileName === 'e2e.js' || fileName === 'e2e.ts' ) ) {
258+ console . debug ( `Adding accessibility event listeners to ${ fileName } ` ) ;
259+ logger . debug ( `Adding accessibility event listeners to ${ fileName } ` ) ;
260+ if ( ( fileName === 'e2e.js' || fileName === 'e2e.ts' || fileName === 'component.ts' || fileName === 'component.js' ) ) {
261+ console . debug ( `Adding accessibility event listeners to ${ file } ` ) ;
262+ logger . debug ( `Adding accessibility event listeners to ${ file } ` ) ;
242263 const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
243264
244265 let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
0 commit comments