Skip to content

Commit 4cd5b6f

Browse files
Refactoring
1 parent 489f236 commit 4cd5b6f

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ const validate = (bsConfig, args) => {
239239
// Detect if the user is not using the right directory structure, and throw an error
240240
if (!Utils.isUndefined(cypressConfigFile.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressConfigFile.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
241241
}
242-
logger.debug("Validating baseurl and integrationFolder in browserstack.json");
243-
if (!Utils.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) && !Utils.isUndefined(bsConfig.run_settings.baseUrl) && bsConfig.run_settings.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", bsConfig.run_settings.baseUrl));
244-
if (!Utils.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) && !Utils.isUndefined(bsConfig.run_settings.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,bsConfig.run_settings.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
242+
else {
243+
logger.debug("Validating baseurl and integrationFolder in browserstack.json");
244+
if (!Utils.isUndefined(bsConfig.run_settings.baseUrl) && bsConfig.run_settings.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", bsConfig.run_settings.baseUrl));
245+
if (!Utils.isUndefined(bsConfig.run_settings.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,bsConfig.run_settings.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
246+
}
245247
} catch(error){
246248
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
247249
}

bin/helpers/constants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ const userMessages = {
7070
UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully",
7171
UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack",
7272
UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
73-
SKIP_CYPRESSCONFIG_INSTALL:
74-
"Skipping Cypress Config Install as the enforce_settings has been passed.",
7573
SKIP_UPLOADING_TESTS:
7674
"Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.",
7775
SKIP_NPM_INSTALL:

bin/helpers/utils.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,29 +1292,28 @@ exports.setConfig = (bsConfig, args) => {
12921292

12931293
// set configs if enforce_settings is passed
12941294
exports.setEnforceSettingsConfig = (bsConfig) => {
1295-
let config_args = (!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.config)) ? bsConfig.run_settings.config : undefined;
1295+
if ( this.isUndefined(bsConfig) || this.isUndefined(bsConfig.run_settings) ) return;
1296+
let config_args = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.config) ? bsConfig.run_settings.config : undefined;
12961297
if ( this.isUndefined(config_args) || !config_args.includes("video") ) {
12971298
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' ;
12981299
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';
12991300
config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
13001301
logger.debug(`Setting video_args for enforce_settings to ${video_args}`);
13011302
}
1302-
if ( (!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.baseUrl)) && (this.isUndefined(config_args) || !config_args.includes("baseUrl")) ) {
1303+
if ( (bsConfig && bsConfig.run_settings && bsConfig.run_settings.baseUrl) && (this.isUndefined(config_args) || !config_args.includes("baseUrl")) ) {
13031304
let base_url_args = 'baseUrl='+bsConfig.run_settings.baseUrl;
13041305
config_args = this.isUndefined(config_args) ? base_url_args : config_args + ',' + base_url_args;
13051306
logger.debug(`Setting base_url_args for enforce_settings to ${base_url_args}`);
13061307
}
13071308
// set specs in config of specpattern to override cypress config
1308-
if(!this.isUndefined(bsConfig) && !this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.specs)) {
1309+
if( this.isNotUndefined(bsConfig.run_settings.specs) && bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE ) {
1310+
// doing this only for cypress 10 and above as --spec is given precedence for cypress 9.
13091311
let spec_pattern_args = 'specPattern="'+bsConfig.run_settings.specs+'"';
1310-
if( bsConfig.run_settings.cypressTestSuiteType !== Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
1311-
spec_pattern_args = 'testFiles="'+bsConfig.run_settings.specs+'"';
1312-
}
13131312
config_args = this.isUndefined(config_args) ? spec_pattern_args : config_args + ',' + spec_pattern_args;
13141313
}
1315-
if ( !this.isUndefined(config_args) ) bsConfig["run_settings"]["config"] = config_args;
1314+
if ( this.isNotUndefined(config_args) ) bsConfig["run_settings"]["config"] = config_args;
13161315
logger.debug(`Setting conifg_args for enforce_settings to ${config_args}`);
1317-
}
1316+
}
13181317

13191318
// blindly send other passed configs with run_settings and handle at backend
13201319
exports.setOtherConfigs = (bsConfig, args) => {

0 commit comments

Comments
 (0)