@@ -22,7 +22,7 @@ const usageReporting = require("./usageReporting"),
2222 config = require ( "../helpers/config" ) ,
2323 pkg = require ( '../../package.json' ) ,
2424 transports = require ( './logger' ) . transports ,
25- { findGitConfig , printBuildLink , isTestObservabilitySession , isBrowserstackInfra , shouldReRunObservabilityTests } = require ( '../testObservability/helper/helper' ) ,
25+ o11yHelpers = require ( '../testObservability/helper/helper' ) ,
2626 { OBSERVABILITY_ENV_VARS , TEST_OBSERVABILITY_REPORTER } = require ( '../testObservability/helper/constants' ) ;
2727
2828const request = require ( 'request' ) ;
@@ -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 }
@@ -480,7 +481,7 @@ exports.setNodeVersion = (bsConfig, args) => {
480481// specs can be passed via command line args as a string
481482// command line args takes precedence over config
482483exports . setUserSpecs = ( bsConfig , args ) => {
483- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
484+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
484485 bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
485486 return ;
486487 }
@@ -580,8 +581,8 @@ exports.setSystemEnvs = (bsConfig) => {
580581 envKeys [ key ] = process . env [ key ] ;
581582 } ) ;
582583
583- let gitConfigPath = findGitConfig ( process . cwd ( ) ) ;
584- if ( ! isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
584+ let gitConfigPath = o11yHelpers . findGitConfig ( process . cwd ( ) ) ;
585+ if ( ! o11yHelpers . isBrowserstackInfra ( ) ) process . env . OBSERVABILITY_GIT_CONFIG_PATH_LOCAL = gitConfigPath ;
585586 if ( gitConfigPath ) {
586587 const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
587588 envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -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 ] ;
@@ -1184,8 +1188,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
11841188 syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
11851189 syncCliLogger . info ( dashboard_url ) ;
11861190 }
1187- if ( isTestObservabilitySession ( ) ) {
1188- printBuildLink ( true , exitCode ) ;
1191+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1192+ o11yHelpers . printBuildLink ( true , exitCode ) ;
11891193 } else {
11901194 process . exit ( exitCode ) ;
11911195 }
@@ -1286,9 +1290,53 @@ 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 ) => {
1291- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1339+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
12921340 bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
12931341 return ;
12941342 }
@@ -1453,14 +1501,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
14531501 process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
14541502}
14551503
1504+ exports . setO11yProcessHooks = ( ( ) => {
1505+ let bindData = { } ;
1506+ let handlerAdded = false ;
1507+ return ( buildId , bsConfig , bsLocal , args , buildReportData ) => {
1508+ bindData . buildId = buildId ;
1509+ bindData . bsConfig = bsConfig ;
1510+ bindData . bsLocal = bsLocal ;
1511+ bindData . args = args ;
1512+ bindData . buildReportData = buildReportData ;
1513+ if ( handlerAdded ) return ;
1514+ handlerAdded = true ;
1515+ process . on ( 'beforeExit' , processO11yExitHandler . bind ( this , bindData ) ) ;
1516+ }
1517+ } ) ( )
1518+
14561519async function processExitHandler ( exitData ) {
14571520 logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
14581521 await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
14591522 await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1460- await printBuildLink ( true ) ;
1523+ await o11yHelpers . printBuildLink ( true ) ;
14611524 process . exit ( 0 ) ;
14621525}
14631526
1527+ async function processO11yExitHandler ( exitData ) {
1528+ if ( exitData . buildId ) {
1529+ await o11yHelpers . printBuildLink ( false ) ;
1530+ } else {
1531+ await o11yHelpers . printBuildLink ( true ) ;
1532+ }
1533+ }
1534+
14641535exports . fetchZipSize = ( fileName ) => {
14651536 try {
14661537 let stats = fs . statSync ( fileName )
@@ -1499,14 +1570,23 @@ exports.fetchFolderSize = async (dir) => {
14991570 }
15001571}
15011572
1502- exports . getVideoConfig = ( cypressConfig ) => {
1573+ exports . getVideoConfig = ( cypressConfig , bsConfig = { } ) => {
15031574 let conf = {
15041575 video : true ,
15051576 videoUploadOnPasses : true
15061577 }
1507- if ( ! this . isUndefined ( cypressConfig . video ) ) conf . video = cypressConfig . video ;
1508- 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+ }
15091587
1588+ // set video in cli config in case of cypress 13 or above as default value is false there.
1589+ this . setVideoCliConfig ( bsConfig , conf ) ;
15101590 logger . debug ( `Setting video = ${ conf . video } ` ) ;
15111591 logger . debug ( `Setting videoUploadOnPasses = ${ conf . videoUploadOnPasses } ` ) ;
15121592 return conf ;
0 commit comments