@@ -434,7 +434,8 @@ exports.setProjectId = (bsConfig, args, cypressConfigFile) => {
434434 } else if ( ! this . isUndefined ( bsConfig . run_settings [ "projectId" ] ) ) {
435435 return bsConfig . run_settings [ "projectId" ] ;
436436 } else {
437- if ( ! this . isUndefined ( cypressConfigFile ) && ! this . isUndefined ( cypressConfigFile [ "projectId" ] ) ) {
437+ // ignore reading cypressconfig if enforce_settings is passed
438+ if ( this . isUndefinedOrFalse ( bsConfig . run_settings . enforce_settings ) && ! this . isUndefined ( cypressConfigFile ) && ! this . isUndefined ( cypressConfigFile [ "projectId" ] ) ) {
438439 return cypressConfigFile [ "projectId" ] ;
439440 }
440441 }
@@ -628,6 +629,8 @@ exports.isPositiveInteger = (str) => {
628629
629630exports . isTrueString = value => ( ! this . isUndefined ( value ) && value . toString ( ) . toLowerCase ( ) === 'true' ) ;
630631
632+ exports . isUndefinedOrFalse = value => ( this . isUndefined ( value ) || value . toString ( ) . toLowerCase ( ) === 'false' ) ;
633+
631634exports . isFloat = ( value ) => Number ( value ) && Number ( value ) % 1 !== 0 ;
632635
633636exports . isInteger = ( value ) => Number . isInteger ( value ) ;
@@ -1077,7 +1080,8 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
10771080 if ( bsConfig . run_settings . cypressTestSuiteType === Constants . CYPRESS_V10_AND_ABOVE_TYPE ) {
10781081 defaultSpecFolder = Constants . DEFAULT_CYPRESS_10_SPEC_PATH
10791082 testFolderPath = defaultSpecFolder
1080- if ( ! this . isUndefined ( cypressConfig ) && ! this . isUndefined ( cypressConfig . e2e ) ) {
1083+ // Read cypress config if enforce_settings is not present
1084+ if ( this . isUndefinedOrFalse ( bsConfig . run_settings . enforce_settings ) && ! this . isUndefined ( cypressConfig ) && ! this . isUndefined ( cypressConfig . e2e ) ) {
10811085 if ( ! this . isUndefined ( cypressConfig . e2e . specPattern ) ) {
10821086 globCypressConfigSpecPatterns = Array . isArray ( cypressConfig . e2e . specPattern ) ?
10831087 cypressConfig . e2e . specPattern : [ cypressConfig . e2e . specPattern ] ;
@@ -1286,6 +1290,50 @@ exports.setConfig = (bsConfig, args) => {
12861290 }
12871291}
12881292
1293+ exports . setVideoCliConfig = ( bsConfig , videoConfig ) => {
1294+ // set cli config for video for cypress 13 and above to attain default value of true.
1295+ if ( this . isUndefined ( videoConfig ) || this . isUndefined ( videoConfig . video ) || this . isUndefined ( videoConfig . videoUploadOnPasses ) || this . isUndefined ( bsConfig ) ) return ;
1296+ let user_cypress_version = ( bsConfig && bsConfig . run_settings && bsConfig . run_settings . cypress_version ) ? bsConfig . run_settings . cypress_version . toString ( ) : undefined ;
1297+ let cypress_major_version = ( user_cypress_version && user_cypress_version . match ( / ^ ( \d + ) / ) ) ? user_cypress_version . split ( "." ) [ 0 ] : undefined ;
1298+ let config_args = ( bsConfig && bsConfig . run_settings && bsConfig . run_settings . config ) ? bsConfig . run_settings . config : undefined ;
1299+ if ( this . isUndefined ( user_cypress_version ) || this . isUndefined ( cypress_major_version ) || parseInt ( cypress_major_version ) >= 13 ) {
1300+ let video_args = `video=${ videoConfig . video } ,videoUploadOnPasses=${ videoConfig . videoUploadOnPasses } ` ;
1301+ config_args = this . isUndefined ( config_args ) ? video_args : config_args + ',' + video_args ;
1302+ logger . debug ( `Setting default video true for cypress 13 and above in cli for cypress version ${ user_cypress_version } with cli args - ${ config_args } ` )
1303+ }
1304+ if ( bsConfig . run_settings && this . isNotUndefined ( config_args ) ) bsConfig [ "run_settings" ] [ "config" ] = config_args ;
1305+ }
1306+
1307+ // set configs if enforce_settings is passed
1308+ exports . setEnforceSettingsConfig = ( bsConfig ) => {
1309+ if ( this . isUndefined ( bsConfig ) || this . isUndefined ( bsConfig . run_settings ) ) return ;
1310+ let config_args = ( bsConfig && bsConfig . run_settings && bsConfig . run_settings . config ) ? bsConfig . run_settings . config : undefined ;
1311+ if ( this . isUndefined ( config_args ) || ! config_args . includes ( "video" ) ) {
1312+ let video_args = ( this . isUndefined ( bsConfig . run_settings . video_config ) || this . isUndefined ( bsConfig . run_settings . video_config . video ) || ! bsConfig . run_settings . video_config . video ) ? 'video=false' : 'video=true' ;
1313+ video_args += ( this . isUndefined ( bsConfig . run_settings . video_config ) || this . isUndefined ( bsConfig . run_settings . video_config . videoUploadOnPasses ) || ! bsConfig . run_settings . video_config . videoUploadOnPasses ) ? ',videoUploadOnPasses=false' : ',videoUploadOnPasses=true' ;
1314+ config_args = this . isUndefined ( config_args ) ? video_args : config_args + ',' + video_args ;
1315+ logger . debug ( `Setting video_args for enforce_settings to ${ video_args } ` ) ;
1316+ }
1317+ if ( ( bsConfig && bsConfig . run_settings && bsConfig . run_settings . baseUrl ) && ( this . isUndefined ( config_args ) || ! config_args . includes ( "baseUrl" ) ) ) {
1318+ let base_url_args = 'baseUrl=' + bsConfig . run_settings . baseUrl ;
1319+ config_args = this . isUndefined ( config_args ) ? base_url_args : config_args + ',' + base_url_args ;
1320+ logger . debug ( `Setting base_url_args for enforce_settings to ${ base_url_args } ` ) ;
1321+ }
1322+ // set specs in config of specpattern to override cypress config
1323+ if ( this . isNotUndefined ( bsConfig . run_settings . specs ) && bsConfig . run_settings . cypressTestSuiteType === Constants . CYPRESS_V10_AND_ABOVE_TYPE && ( this . isUndefined ( config_args ) || ! config_args . includes ( "specPattern" ) ) ) {
1324+ // doing this only for cypress 10 and above as --spec is given precedence for cypress 9.
1325+ let specConfigs = bsConfig . run_settings . specs ;
1326+ // if multiple specs are passed, convert it into an array.
1327+ if ( specConfigs && specConfigs . includes ( ',' ) ) {
1328+ specConfigs = JSON . stringify ( specConfigs . split ( ',' ) ) ;
1329+ }
1330+ let spec_pattern_args = 'specPattern="' + specConfigs + '"' ;
1331+ config_args = this . isUndefined ( config_args ) ? spec_pattern_args : config_args + ',' + spec_pattern_args ;
1332+ }
1333+ if ( this . isNotUndefined ( config_args ) ) bsConfig [ "run_settings" ] [ "config" ] = config_args ;
1334+ logger . debug ( `Setting conifg_args for enforce_settings to ${ config_args } ` ) ;
1335+ }
1336+
12891337// blindly send other passed configs with run_settings and handle at backend
12901338exports . setOtherConfigs = ( bsConfig , args ) => {
12911339 if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
@@ -1522,14 +1570,23 @@ exports.fetchFolderSize = async (dir) => {
15221570 }
15231571}
15241572
1525- exports . getVideoConfig = ( cypressConfig ) => {
1573+ exports . getVideoConfig = ( cypressConfig , bsConfig = { } ) => {
15261574 let conf = {
15271575 video : true ,
15281576 videoUploadOnPasses : true
15291577 }
1530- if ( ! this . isUndefined ( cypressConfig . video ) ) conf . video = cypressConfig . video ;
1531- if ( ! this . isUndefined ( cypressConfig . videoUploadOnPasses ) ) conf . videoUploadOnPasses = cypressConfig . videoUploadOnPasses ;
1578+ // Reading bsconfig in case of enforce_settings
1579+ if ( this . isUndefined ( bsConfig . run_settings ) || this . isUndefinedOrFalse ( bsConfig . run_settings . enforce_settings ) ) {
1580+ if ( ! this . isUndefined ( cypressConfig . video ) ) conf . video = cypressConfig . video ;
1581+ if ( ! this . isUndefined ( cypressConfig . videoUploadOnPasses ) ) conf . videoUploadOnPasses = cypressConfig . videoUploadOnPasses ;
1582+ }
1583+ else {
1584+ if ( ! this . isUndefined ( bsConfig . run_settings ) && ! this . isUndefined ( bsConfig . run_settings . video ) ) conf . video = bsConfig . run_settings . video ;
1585+ if ( ! this . isUndefined ( bsConfig . run_settings ) && ! this . isUndefined ( bsConfig . run_settings . videoUploadOnPasses ) ) conf . videoUploadOnPasses = bsConfig . run_settings . videoUploadOnPasses ;
1586+ }
15321587
1588+ // set video in cli config in case of cypress 13 or above as default value is false there.
1589+ this . setVideoCliConfig ( bsConfig , conf ) ;
15331590 logger . debug ( `Setting video = ${ conf . video } ` ) ;
15341591 logger . debug ( `Setting videoUploadOnPasses = ${ conf . videoUploadOnPasses } ` ) ;
15351592 return conf ;
0 commit comments