@@ -405,25 +405,24 @@ exports.setRecordKeyFlag = (bsConfig, args) => {
405
405
return bsConfig . run_settings [ "record-key" ] ;
406
406
}
407
407
408
- exports . setProjectId = ( bsConfig , args ) => {
408
+ exports . setProjectId = ( bsConfig , args , cypressConfigFile ) => {
409
409
if ( ! this . isUndefined ( args [ "projectId" ] ) ) {
410
410
return args [ "projectId" ] ;
411
411
} else if ( ! this . isUndefined ( process . env . CYPRESS_PROJECT_ID ) ) {
412
412
return process . env . CYPRESS_PROJECT_ID ;
413
413
} else if ( ! this . isUndefined ( bsConfig . run_settings [ "projectId" ] ) ) {
414
414
return bsConfig . run_settings [ "projectId" ] ;
415
415
} else {
416
- let cypressConfigFile = this . getCypressConfigFile ( bsConfig ) ;
417
416
if ( ! this . isUndefined ( cypressConfigFile ) && ! this . isUndefined ( cypressConfigFile [ "projectId" ] ) ) {
418
417
return cypressConfigFile [ "projectId" ] ;
419
418
}
420
419
}
421
420
}
422
421
423
- exports . setRecordCaps = ( bsConfig , args ) => {
422
+ exports . setRecordCaps = ( bsConfig , args , cypressConfigFile ) => {
424
423
bsConfig . run_settings [ "record" ] = this . setRecordFlag ( bsConfig , args ) ;
425
424
bsConfig . run_settings [ "record-key" ] = this . setRecordKeyFlag ( bsConfig , args ) ;
426
- bsConfig . run_settings [ "projectId" ] = this . setProjectId ( bsConfig , args ) ;
425
+ bsConfig . run_settings [ "projectId" ] = this . setProjectId ( bsConfig , args , cypressConfigFile ) ;
427
426
}
428
427
429
428
exports . verifyNodeVersionOption = ( ) => {
@@ -987,15 +986,69 @@ exports.getFilesToIgnore = (runSettings, excludeFiles, logging = true) => {
987
986
}
988
987
989
988
exports . getNumberOfSpecFiles = ( bsConfig , args , cypressConfig ) => {
990
- let defaultSpecFolder = Constants . DEFAULT_CYPRESS_SPEC_PATH ;
989
+ let defaultSpecFolder
990
+ let testFolderPath
991
+ let globCypressConfigSpecPatterns = [ ]
992
+ let globSearchPattern = this . sanitizeSpecsPattern ( bsConfig . run_settings . specs ) ;
993
+
991
994
if ( bsConfig . run_settings . cypressTestSuiteType === Constants . CYPRESS_V10_AND_ABOVE_TYPE ) {
992
- defaultSpecFolder = Constants . DEFAULT_CYPRESS_10_SPEC_PATH ;
995
+ defaultSpecFolder = Constants . DEFAULT_CYPRESS_10_SPEC_PATH
996
+ testFolderPath = defaultSpecFolder
997
+ if ( ! this . isUndefined ( cypressConfig ) && ! this . isUndefined ( cypressConfig . e2e ) ) {
998
+ if ( ! this . isUndefined ( cypressConfig . e2e . specPattern ) ) {
999
+ globCypressConfigSpecPatterns = Array . isArray ( cypressConfig . e2e . specPattern ) ?
1000
+ cypressConfig . e2e . specPattern : [ cypressConfig . e2e . specPattern ] ;
1001
+ } else {
1002
+ console . log ( 'herer' , [ `${ testFolderPath } /**/*.+(${ Constants . specFileTypes . join ( "|" ) } )` ] )
1003
+ globCypressConfigSpecPatterns = [ `${ testFolderPath } /**/*.+(${ Constants . specFileTypes . join ( "|" ) } )` ]
1004
+ }
1005
+ } else {
1006
+ // if not able read cypress config, use bstack specs arg(existing logic, which is not correct)
1007
+ globCypressConfigSpecPatterns = globSearchPattern ? [ globSearchPattern ] : [ `${ testFolderPath } /**/*.+(${ Constants . specFileTypes . join ( "|" ) } )` ]
1008
+ }
1009
+ } else {
1010
+ defaultSpecFolder = Constants . DEFAULT_CYPRESS_SPEC_PATH
1011
+ // console.log('cypressConfig.integrationFolder', cypressConfig.integrationFolder)
1012
+ let testFolderPath = cypressConfig . integrationFolder && cypressConfig . integrationFolder !== '.' ?
1013
+ cypressConfig . integrationFolder : defaultSpecFolder ;
1014
+ if ( ! this . isUndefined ( cypressConfig . testFiles ) ) {
1015
+ if ( Array . isArray ( cypressConfig . testFiles ) ) {
1016
+ cypressConfig . testFiles . forEach ( specPattern => {
1017
+ globCypressConfigSpecPatterns . push ( `${ testFolderPath } /${ specPattern } ` )
1018
+ } ) ;
1019
+ } else {
1020
+ globCypressConfigSpecPatterns = [ `${ testFolderPath } /${ specPattern } ` ]
1021
+ }
1022
+ } else {
1023
+ globCypressConfigSpecPatterns = [ `${ testFolderPath } /**/*.+(${ Constants . specFileTypes . join ( "|" ) } )` ]
1024
+ }
993
1025
}
994
- let testFolderPath = cypressConfig . integrationFolder || defaultSpecFolder ;
995
- let globSearchPattern = this . sanitizeSpecsPattern ( bsConfig . run_settings . specs ) || `${ testFolderPath } /**/*.+(${ Constants . specFileTypes . join ( "|" ) } )` ;
1026
+
996
1027
let ignoreFiles = args . exclude || bsConfig . run_settings . exclude ;
997
- let files = glob . sync ( globSearchPattern , { cwd : bsConfig . run_settings . cypressProjectDir , matchBase : true , ignore : ignoreFiles } ) ;
998
- logger . debug ( `${ files ? files . length : 0 } spec files found at ${ testFolderPath } ` ) ;
1028
+ // TODO: remove console logs
1029
+ let fileMatchedWithConfigSpecPattern = [ ] ;
1030
+ globCypressConfigSpecPatterns . forEach ( specPattern => {
1031
+ fileMatchedWithConfigSpecPattern . push (
1032
+ ...glob . sync ( specPattern , {
1033
+ cwd : bsConfig . run_settings . cypressProjectDir , matchBase : true , ignore : ignoreFiles
1034
+ } )
1035
+ ) ;
1036
+ } ) ;
1037
+
1038
+ console . log ( 'configSpecPattern' , fileMatchedWithConfigSpecPattern )
1039
+ let files
1040
+
1041
+ if ( globSearchPattern ) {
1042
+ let fileMatchedWithBstackSpecPattern = glob . sync ( globSearchPattern , {
1043
+ cwd : bsConfig . run_settings . cypressProjectDir , matchBase : true , ignore : ignoreFiles
1044
+ } ) ;
1045
+ console . log ( 'specArg' , fileMatchedWithBstackSpecPattern ) ;
1046
+ files = fileMatchedWithBstackSpecPattern . filter ( file => fileMatchedWithConfigSpecPattern . includes ( file ) )
1047
+ } else {
1048
+ files = fileMatchedWithConfigSpecPattern ;
1049
+ }
1050
+ console . log ( 'files' , files )
1051
+ logger . debug ( `${ files ? files . length : 0 } spec files found` ) ;
999
1052
return files ;
1000
1053
} ;
1001
1054
0 commit comments