@@ -21,7 +21,7 @@ exports.checkAccessibilityPlatform = (user_config) => {
21
21
}
22
22
} )
23
23
} catch { }
24
-
24
+
25
25
return accessibility ;
26
26
}
27
27
@@ -113,35 +113,33 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
113
113
114
114
} catch ( error ) {
115
115
if ( error . response ) {
116
- logger . error ( "Incorrect Cred" )
116
+ logger . error ( "Incorrect Cred" ) ;
117
117
logger . error (
118
118
`Exception while creating test run for BrowserStack Accessibility Automation: ${
119
119
error . response . status
120
- } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } `
120
+ } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) }
121
+ `
121
122
) ;
122
- } else {
123
- if ( error . message === 'Invalid configuration passed.' ) {
124
- logger . error ( "Invalid configuration passed." )
125
- logger . error (
126
- `Exception while creating test run for BrowserStack Accessibility Automation: ${
127
- error . message || error . stack
128
- } `
129
- ) ;
130
- for ( const errorkey of error . errors ) {
131
- logger . error ( errorkey . message ) ;
132
- }
133
-
134
- } else {
135
- logger . error (
136
- `Exception while creating test run for BrowserStack Accessibility Automation: ${
137
- error . message || error . stack
138
- } `
139
- ) ;
123
+ } else if ( error . message === 'Invalid configuration passed.' ) {
124
+ logger . error ( "Invalid configuration passed." ) ;
125
+ logger . error (
126
+ `Exception while creating test run for BrowserStack Accessibility Automation: ${
127
+ error . message || error . stack
128
+ } `
129
+ ) ;
130
+ for ( const errorkey of error . errors ) {
131
+ logger . error ( errorkey . message ) ;
140
132
}
141
- // since create accessibility session failed
142
- process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
143
- user_config . run_settings . accessibility = false ;
133
+ } else {
134
+ logger . error (
135
+ `Exception while creating test run for BrowserStack Accessibility Automation: ${
136
+ error . message || error . stack
137
+ } `
138
+ ) ;
144
139
}
140
+ // since create accessibility session failed
141
+ process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
142
+ user_config . run_settings . accessibility = false ;
145
143
}
146
144
}
147
145
@@ -216,22 +214,52 @@ const getAccessibilityCypressCommandEventListener = (extName) => {
216
214
217
215
exports . setAccessibilityEventListeners = ( bsConfig ) => {
218
216
try {
219
- // Searching form command.js recursively
217
+
220
218
const supportFilesData = helper . getSupportFiles ( bsConfig , true ) ;
221
219
if ( ! supportFilesData . supportFile ) return ;
222
- glob ( process . cwd ( ) + supportFilesData . supportFile , { } , ( err , files ) => {
223
- if ( err ) return logger . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
220
+
221
+ const isPattern = glob . hasMagic ( supportFilesData . supportFile ) ;
222
+ if ( ! isPattern ) {
223
+ logger . debug ( `Using user defined support file: ${ supportFilesData . supportFile } ` ) ;
224
+ let file ;
225
+ try {
226
+ file = process . cwd ( ) + supportFilesData . supportFile ;
227
+ const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
228
+ let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
229
+ const alreadyIncludes = defaultFileContent . includes ( cypressCommandEventListener ) ;
230
+ if ( ! alreadyIncludes ) {
231
+ let newFileContent = defaultFileContent +
232
+ '\n' +
233
+ cypressCommandEventListener +
234
+ '\n' ;
235
+ fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
236
+ supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
237
+ }
238
+ } catch ( e ) {
239
+ logger . debug ( `Unable to modify file contents for ${ file } to set event listeners with error ${ e } ` , true , e ) ;
240
+ }
241
+ return ;
242
+ }
243
+
244
+ const globPattern = process . cwd ( ) + supportFilesData . supportFile ;
245
+ glob ( globPattern , { } , ( err , files ) => {
246
+ if ( err ) {
247
+ logger . debug ( 'EXCEPTION IN BUILD START EVENT : Unable to parse cypress support files' ) ;
248
+ return ;
249
+ }
250
+
224
251
files . forEach ( file => {
225
252
try {
226
- if ( ! file . includes ( 'commands.js' ) && ! file . includes ( 'commands.ts' ) ) {
253
+ const fileName = path . basename ( file ) ;
254
+ if ( [ 'e2e.js' , 'e2e.ts' , 'component.ts' , 'component.js' ] . includes ( fileName ) && ! file . includes ( 'node_modules' ) ) {
255
+
227
256
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
228
-
229
257
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
230
258
if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
231
- let newFileContent = defaultFileContent +
259
+ let newFileContent = defaultFileContent +
232
260
'\n' +
233
261
cypressCommandEventListener +
234
- '\n'
262
+ '\n' ;
235
263
fs . writeFileSync ( file , newFileContent , { encoding : 'utf-8' } ) ;
236
264
supportFileContentMap [ file ] = supportFilesData . cleanupParams ? supportFilesData . cleanupParams : defaultFileContent ;
237
265
}
0 commit comments