@@ -22,7 +22,7 @@ const usageReporting = require("./usageReporting"),
22
22
config = require ( "../helpers/config" ) ,
23
23
pkg = require ( '../../package.json' ) ,
24
24
transports = require ( './logger' ) . transports ,
25
- { findGitConfig , printBuildLink , isTestObservabilitySession , isBrowserstackInfra , shouldReRunObservabilityTests } = require ( '../testObservability/helper/helper' ) ,
25
+ o11yHelpers = require ( '../testObservability/helper/helper' ) ,
26
26
{ OBSERVABILITY_ENV_VARS , TEST_OBSERVABILITY_REPORTER } = require ( '../testObservability/helper/constants' ) ;
27
27
28
28
const request = require ( 'request' ) ;
@@ -434,7 +434,8 @@ exports.setProjectId = (bsConfig, args, cypressConfigFile) => {
434
434
} else if ( ! this . isUndefined ( bsConfig . run_settings [ "projectId" ] ) ) {
435
435
return bsConfig . run_settings [ "projectId" ] ;
436
436
} 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" ] ) ) {
438
439
return cypressConfigFile [ "projectId" ] ;
439
440
}
440
441
}
@@ -480,7 +481,7 @@ exports.setNodeVersion = (bsConfig, args) => {
480
481
// specs can be passed via command line args as a string
481
482
// command line args takes precedence over config
482
483
exports . setUserSpecs = ( bsConfig , args ) => {
483
- if ( isBrowserstackInfra ( ) && isTestObservabilitySession ( ) && shouldReRunObservabilityTests ( ) ) {
484
+ if ( o11yHelpers . isBrowserstackInfra ( ) && o11yHelpers . isTestObservabilitySession ( ) && o11yHelpers . shouldReRunObservabilityTests ( ) ) {
484
485
bsConfig . run_settings . specs = process . env . BROWSERSTACK_RERUN_TESTS ;
485
486
return ;
486
487
}
@@ -580,8 +581,8 @@ exports.setSystemEnvs = (bsConfig) => {
580
581
envKeys [ key ] = process . env [ key ] ;
581
582
} ) ;
582
583
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 ;
585
586
if ( gitConfigPath ) {
586
587
const relativePathFromGitConfig = path . relative ( gitConfigPath , process . cwd ( ) ) ;
587
588
envKeys [ "OBSERVABILITY_GIT_CONFIG_PATH" ] = relativePathFromGitConfig ? relativePathFromGitConfig : 'DEFAULT' ;
@@ -628,6 +629,8 @@ exports.isPositiveInteger = (str) => {
628
629
629
630
exports . isTrueString = value => ( ! this . isUndefined ( value ) && value . toString ( ) . toLowerCase ( ) === 'true' ) ;
630
631
632
+ exports . isUndefinedOrFalse = value => ( this . isUndefined ( value ) || value . toString ( ) . toLowerCase ( ) === 'false' ) ;
633
+
631
634
exports . isFloat = ( value ) => Number ( value ) && Number ( value ) % 1 !== 0 ;
632
635
633
636
exports . isInteger = ( value ) => Number . isInteger ( value ) ;
@@ -1077,7 +1080,8 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
1077
1080
if ( bsConfig . run_settings . cypressTestSuiteType === Constants . CYPRESS_V10_AND_ABOVE_TYPE ) {
1078
1081
defaultSpecFolder = Constants . DEFAULT_CYPRESS_10_SPEC_PATH
1079
1082
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 ) ) {
1081
1085
if ( ! this . isUndefined ( cypressConfig . e2e . specPattern ) ) {
1082
1086
globCypressConfigSpecPatterns = Array . isArray ( cypressConfig . e2e . specPattern ) ?
1083
1087
cypressConfig . e2e . specPattern : [ cypressConfig . e2e . specPattern ] ;
@@ -1184,8 +1188,8 @@ exports.handleSyncExit = (exitCode, dashboard_url) => {
1184
1188
syncCliLogger . info ( Constants . userMessages . BUILD_REPORT_MESSAGE ) ;
1185
1189
syncCliLogger . info ( dashboard_url ) ;
1186
1190
}
1187
- if ( isTestObservabilitySession ( ) ) {
1188
- printBuildLink ( true , exitCode ) ;
1191
+ if ( o11yHelpers . isTestObservabilitySession ( ) ) {
1192
+ o11yHelpers . printBuildLink ( true , exitCode ) ;
1189
1193
} else {
1190
1194
process . exit ( exitCode ) ;
1191
1195
}
@@ -1286,9 +1290,53 @@ exports.setConfig = (bsConfig, args) => {
1286
1290
}
1287
1291
}
1288
1292
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
+
1289
1337
// blindly send other passed configs with run_settings and handle at backend
1290
1338
exports . setOtherConfigs = ( bsConfig , args ) => {
1291
- if ( isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1339
+ if ( o11yHelpers . isTestObservabilitySession ( ) && process . env . BS_TESTOPS_JWT ) {
1292
1340
bsConfig [ "run_settings" ] [ "reporter" ] = TEST_OBSERVABILITY_REPORTER ;
1293
1341
return ;
1294
1342
}
@@ -1453,14 +1501,37 @@ exports.setProcessHooks = (buildId, bsConfig, bsLocal, args, buildReportData) =>
1453
1501
process . on ( 'uncaughtException' , processExitHandler . bind ( this , bindData ) ) ;
1454
1502
}
1455
1503
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
+
1456
1519
async function processExitHandler ( exitData ) {
1457
1520
logger . warn ( Constants . userMessages . PROCESS_KILL_MESSAGE ) ;
1458
1521
await this . stopBrowserStackBuild ( exitData . bsConfig , exitData . args , exitData . buildId , null , exitData . buildReportData ) ;
1459
1522
await this . stopLocalBinary ( exitData . bsConfig , exitData . bsLocalInstance , exitData . args , null , exitData . buildReportData ) ;
1460
- await printBuildLink ( true ) ;
1523
+ await o11yHelpers . printBuildLink ( true ) ;
1461
1524
process . exit ( 0 ) ;
1462
1525
}
1463
1526
1527
+ async function processO11yExitHandler ( exitData ) {
1528
+ if ( exitData . buildId ) {
1529
+ await o11yHelpers . printBuildLink ( false ) ;
1530
+ } else {
1531
+ await o11yHelpers . printBuildLink ( true ) ;
1532
+ }
1533
+ }
1534
+
1464
1535
exports . fetchZipSize = ( fileName ) => {
1465
1536
try {
1466
1537
let stats = fs . statSync ( fileName )
@@ -1499,14 +1570,23 @@ exports.fetchFolderSize = async (dir) => {
1499
1570
}
1500
1571
}
1501
1572
1502
- exports . getVideoConfig = ( cypressConfig ) => {
1573
+ exports . getVideoConfig = ( cypressConfig , bsConfig = { } ) => {
1503
1574
let conf = {
1504
1575
video : true ,
1505
1576
videoUploadOnPasses : true
1506
1577
}
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
+ }
1509
1587
1588
+ // set video in cli config in case of cypress 13 or above as default value is false there.
1589
+ this . setVideoCliConfig ( bsConfig , conf ) ;
1510
1590
logger . debug ( `Setting video = ${ conf . video } ` ) ;
1511
1591
logger . debug ( `Setting videoUploadOnPasses = ${ conf . videoUploadOnPasses } ` ) ;
1512
1592
return conf ;
0 commit comments