Skip to content

Commit

Permalink
Fix for specs passed as array in enforce_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharanbrowserstack committed Dec 1, 2023
1 parent c4b5ab7 commit 4e36fdb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 8 additions & 3 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ exports.setVideoCliConfig = (bsConfig, videoConfig) => {
let cypress_major_version = (user_cypress_version && user_cypress_version.match(/^(\d+)/)) ? user_cypress_version.split(".")[0] : undefined;
let config_args = (bsConfig && bsConfig.run_settings && bsConfig.run_settings.config) ? bsConfig.run_settings.config : undefined;
if(this.isUndefined(user_cypress_version) || this.isUndefined(cypress_major_version) || parseInt(cypress_major_version) >= 13 ) {
logger.info('Setting default video for cypress 13 and above');
logger.debug('Setting default video for cypress 13 and above');
let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
logger.debug(`Setting video true in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
Expand All @@ -1321,9 +1321,14 @@ exports.setEnforceSettingsConfig = (bsConfig) => {
logger.debug(`Setting base_url_args for enforce_settings to ${base_url_args}`);
}
// set specs in config of specpattern to override cypress config
if( this.isNotUndefined(bsConfig.run_settings.specs) && bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE ) {
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")) ) {
// doing this only for cypress 10 and above as --spec is given precedence for cypress 9.
let spec_pattern_args = 'specPattern="'+bsConfig.run_settings.specs+'"';
let specConfigs = bsConfig.run_settings.specs;
// if multiple specs are passed, convert it into an array.
if(specConfigs && specConfigs.includes(',')) {
specConfigs = JSON.stringify(bsConfig.run_settings.specs.split(','));
}
let spec_pattern_args = 'specPattern="'+specConfigs+'"';
config_args = this.isUndefined(config_args) ? spec_pattern_args : config_args + ',' + spec_pattern_args;
}
if ( this.isNotUndefined(config_args) ) bsConfig["run_settings"]["config"] = config_args;
Expand Down
12 changes: 11 additions & 1 deletion test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3101,7 +3101,7 @@ describe('utils', () => {
utils.setEnforceSettingsConfig(bsConfig);
expect(args.config).to.be.eql(bsConfig.run_settings.config);
});
it('the specPattern config should be assigned to bsconfig run_settings config', () => {
it('the specPattern config should be assigned as strings for single string to bsconfig run_settings config', () => {
let bsConfig = {
run_settings: { specs: 'somerandomspecs', cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE' },
};
Expand All @@ -3111,6 +3111,16 @@ describe('utils', () => {
utils.setEnforceSettingsConfig(bsConfig);
expect(args.config).to.be.eql(bsConfig.run_settings.config);
});
it('the specPattern config should be assigned as array for multiple spec strings to bsconfig run_settings config', () => {
let bsConfig = {
run_settings: { specs: 'somerandomspecs1,somerandomspecs2', cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE' },
};
let args = {
config: 'video=false,videoUploadOnPasses=false,specPattern="["somerandomspecs1","somerandomspecs2"]"'
}
utils.setEnforceSettingsConfig(bsConfig);
expect(args.config).to.be.eql(bsConfig.run_settings.config);
});
it('the testFiles config should be assigned to bsconfig run_settings config', () => {
let bsConfig = {
run_settings: { specs: 'somerandomspecs', cypressTestSuiteType: 'CYPRESS_V9_AND_OLDER_TYPE' },
Expand Down

0 comments on commit 4e36fdb

Please sign in to comment.