@@ -16,6 +16,7 @@ const gitconfig = require('gitconfiglocal');
16
16
const { spawn, execSync } = require ( 'child_process' ) ;
17
17
const glob = require ( 'glob' ) ;
18
18
const pGitconfig = promisify ( gitconfig ) ;
19
+ const { readCypressConfigFile } = require ( './readCypressConfigUtil' ) ;
19
20
const CrashReporter = require ( '../testObservability/crashReporter' ) ;
20
21
21
22
exports . debug = ( text , shouldReport = false , throwable = null ) => {
@@ -313,3 +314,71 @@ exports.setBrowserstackCypressCliDependency = (bsConfig) => {
313
314
}
314
315
}
315
316
}
317
+
318
+ exports . deleteSupportFileOrDir = ( fileOrDirPath ) => {
319
+ try {
320
+ if ( fs . existsSync ( fileOrDirPath ) ) {
321
+ if ( fs . lstatSync ( fileOrDirPath ) . isDirectory ( ) ) {
322
+ fs . readdirSync ( fileOrDirPath ) . forEach ( ( file ) => {
323
+ const currentPath = path . join ( fileOrDirPath , file ) ;
324
+ fs . unlinkSync ( currentPath ) ;
325
+ } ) ;
326
+ fs . rmdirSync ( fileOrDirPath ) ;
327
+ } else {
328
+ fs . unlinkSync ( fileOrDirPath ) ;
329
+ }
330
+ }
331
+ } catch ( err ) { }
332
+ }
333
+
334
+ exports . getSupportFiles = ( bsConfig , isA11y ) => {
335
+ let extension = null ;
336
+ try {
337
+ extension = bsConfig . run_settings . cypress_config_file . split ( '.' ) . pop ( ) ;
338
+ } catch ( err ) { }
339
+ let supportFile = '/**/cypress/support/**/*.{js,ts}' ;
340
+ let cleanupParams = { } ;
341
+ let userSupportFile = null ;
342
+ try {
343
+ const completeCypressConfigFile = readCypressConfigFile ( bsConfig )
344
+ let cypressConfigFile = { } ;
345
+ if ( ! utils . isUndefined ( completeCypressConfigFile ) ) {
346
+ cypressConfigFile = ! utils . isUndefined ( completeCypressConfigFile . default ) ? completeCypressConfigFile . default : completeCypressConfigFile
347
+ }
348
+ userSupportFile = cypressConfigFile . e2e ?. supportFile !== null ? cypressConfigFile . e2e ?. supportFile : cypressConfigFile . component ?. supportFile !== null ? cypressConfigFile . component ?. supportFile : cypressConfigFile . supportFile ;
349
+ if ( userSupportFile == false && extension ) {
350
+ const supportFolderPath = path . join ( process . cwd ( ) , 'cypress' , 'support' ) ;
351
+ if ( ! fs . existsSync ( supportFolderPath ) ) {
352
+ fs . mkdirSync ( supportFolderPath ) ;
353
+ cleanupParams . deleteSupportDir = true ;
354
+ }
355
+ const supportFilePath = path . join ( supportFolderPath , `tmpBstackSupportFile.${ extension } ` ) ;
356
+ fs . writeFileSync ( supportFilePath , "" ) ;
357
+ supportFile = `/cypress/support/tmpBstackSupportFile.${ extension } ` ;
358
+ const currEnvVars = bsConfig . run_settings . system_env_vars ;
359
+ const supportFileEnv = `CYPRESS_SUPPORT_FILE=${ supportFile . substring ( 1 ) } ` ;
360
+ if ( ! currEnvVars ) {
361
+ bsConfig . run_settings . system_env_vars = [ supportFileEnv ] ;
362
+ } else {
363
+ bsConfig . run_settings . system_env_vars = [ ...currEnvVars , supportFileEnv ] ;
364
+ }
365
+ cleanupParams . deleteSupportFile = true ;
366
+ } else if ( typeof userSupportFile == 'string' ) {
367
+ if ( userSupportFile . startsWith ( '${' ) && userSupportFile . endsWith ( '}' ) ) {
368
+ /* Template strings to reference environment variables */
369
+ const envVar = userSupportFile . substring ( 2 , userSupportFile . length - 1 ) ;
370
+ supportFile = process . env [ envVar ] ;
371
+ } else {
372
+ /* Single file / glob pattern */
373
+ supportFile = userSupportFile ;
374
+ }
375
+ } else if ( Array . isArray ( userSupportFile ) ) {
376
+ supportFile = userSupportFile [ 0 ] ;
377
+ }
378
+ } catch ( err ) { }
379
+ if ( supportFile && supportFile [ 0 ] != '/' ) supportFile = '/' + supportFile ;
380
+ return {
381
+ supportFile,
382
+ cleanupParams : Object . keys ( cleanupParams ) . length ? cleanupParams : null
383
+ } ;
384
+ }
0 commit comments