Skip to content

Commit c4b5ab7

Browse files
Default video true implementation for cypress 13
1 parent 4cd5b6f commit c4b5ab7

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

bin/helpers/utils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,21 @@ exports.setConfig = (bsConfig, args) => {
12901290
}
12911291
}
12921292

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+
logger.info('Setting default video for cypress 13 and above');
1301+
let video_args = `video=${videoConfig.video},videoUploadOnPasses=${videoConfig.videoUploadOnPasses}`;
1302+
config_args = this.isUndefined(config_args) ? video_args : config_args + ',' + video_args;
1303+
logger.debug(`Setting video true in cli for cypress version ${user_cypress_version} with cli args - ${config_args}`)
1304+
}
1305+
if (bsConfig.run_settings && this.isNotUndefined(config_args)) bsConfig["run_settings"]["config"] = config_args;
1306+
}
1307+
12931308
// set configs if enforce_settings is passed
12941309
exports.setEnforceSettingsConfig = (bsConfig) => {
12951310
if ( this.isUndefined(bsConfig) || this.isUndefined(bsConfig.run_settings) ) return;
@@ -1536,11 +1551,13 @@ exports.getVideoConfig = (cypressConfig, bsConfig = {}) => {
15361551
// Reading from bsconfig first to give precedance and cypress config will be empty in case of enforce_settings
15371552
if (!this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.video)) conf.video = bsConfig.run_settings.video;
15381553
if (!this.isUndefined(bsConfig.run_settings) && !this.isUndefined(bsConfig.run_settings.videoUploadOnPasses)) conf.videoUploadOnPasses = bsConfig.run_settings.videoUploadOnPasses;
1539-
if ( this.isUndefined(bsConfig.run_settings) || this.isUndefined(bsConfig.run_settings.enforce_settings) ) {
1554+
if ( this.isUndefined(bsConfig.run_settings) || this.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) ) {
15401555
if (!this.isUndefined(cypressConfig.video)) conf.video = cypressConfig.video;
15411556
if (!this.isUndefined(cypressConfig.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressConfig.videoUploadOnPasses;
15421557
}
15431558

1559+
// set video in cli config in case of cypress 13 or above as default value is false there.
1560+
this.setVideoCliConfig(bsConfig,conf);
15441561
logger.debug(`Setting video = ${conf.video}`);
15451562
logger.debug(`Setting videoUploadOnPasses = ${conf.videoUploadOnPasses}`);
15461563
return conf;

test/unit/bin/helpers/utils.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,41 @@ describe('utils', () => {
30553055
});
30563056
});
30573057

3058+
describe('setVideoCliConfig', () => {
3059+
it('the args should be empty if any of videoconfig or bsconfig is undefined', () => {
3060+
let bsConfig = {
3061+
run_settings: {},
3062+
};
3063+
let videoConfig = {
3064+
};
3065+
utils.setVideoCliConfig(bsConfig, videoConfig);
3066+
expect(undefined).to.be.eql(bsConfig.run_settings.config);
3067+
});
3068+
it('the config should have video true if video is passed true', () => {
3069+
let bsConfig = {
3070+
run_settings: {},
3071+
};
3072+
let videoConfig = {video:true, videoUploadOnPasses:true};
3073+
let outputConfig = {
3074+
config: 'video=true,videoUploadOnPasses=true'
3075+
};
3076+
utils.setVideoCliConfig(bsConfig, videoConfig);
3077+
expect(outputConfig.config).to.be.eql(bsConfig.run_settings.config);
3078+
});
3079+
it('the config should have config with video false if video is passed false', () => {
3080+
let bsConfig = {
3081+
run_settings: {},
3082+
};
3083+
let videoConfig = {video:false, videoUploadOnPasses:true};
3084+
let outputConfig = {
3085+
config: 'video=false,videoUploadOnPasses=true'
3086+
};
3087+
utils.setVideoCliConfig(bsConfig, videoConfig);
3088+
expect(outputConfig.config).to.be.eql(bsConfig.run_settings.config);
3089+
});
3090+
});
3091+
3092+
30583093
describe('setEnforceSettingsConfig', () => {
30593094
it('the video config should be assigned to bsconfig run_settings config', () => {
30603095
let bsConfig = {
@@ -3081,7 +3116,7 @@ describe('utils', () => {
30813116
run_settings: { specs: 'somerandomspecs', cypressTestSuiteType: 'CYPRESS_V9_AND_OLDER_TYPE' },
30823117
};
30833118
let args = {
3084-
config: 'video=false,videoUploadOnPasses=false,testFiles="somerandomspecs"'
3119+
config: 'video=false,videoUploadOnPasses=false'
30853120
}
30863121
utils.setEnforceSettingsConfig(bsConfig);
30873122
expect(args.config).to.be.eql(bsConfig.run_settings.config);
@@ -3463,6 +3498,43 @@ describe('utils', () => {
34633498
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false})).to.be.eql({video: false, videoUploadOnPasses: false});
34643499
});
34653500

3501+
it('should add default video config in cli config only for cyp 13', () => {
3502+
let bsConfig = {
3503+
run_settings: {cypress_version: '13.latest'},
3504+
};
3505+
let outputConfig = 'video=true,videoUploadOnPasses=true';
3506+
utils.getVideoConfig({}, bsConfig);
3507+
expect(outputConfig).to.be.eql(bsConfig.run_settings.config);
3508+
});
3509+
3510+
it('should add not default video config in cli config only for cyp 12 or below', () => {
3511+
let bsConfig = {
3512+
run_settings: {cypress_version: '12.latest'},
3513+
};
3514+
utils.getVideoConfig({}, bsConfig);
3515+
expect(undefined).to.be.eql(bsConfig.run_settings.config);
3516+
});
3517+
3518+
it('should add bstack json video config in cli config if none in cypress config for cyp 13', () => {
3519+
let bsConfig = {
3520+
run_settings: {cypress_version: '13.latest', video: true, videoUploadOnPasses: false}
3521+
};
3522+
let cypressConfig = {};
3523+
let outputConfig = 'video=true,videoUploadOnPasses=false';
3524+
utils.getVideoConfig(cypressConfig, bsConfig);
3525+
expect(outputConfig).to.be.eql(bsConfig.run_settings.config);
3526+
});
3527+
3528+
it('should add cypress config video config in cli config over bstack json for cyp 13', () => {
3529+
let bsConfig = {
3530+
run_settings: {cypress_version: '13.latest'},
3531+
};
3532+
let cypressConfig = {video: false};
3533+
let outputConfig = 'video=false,videoUploadOnPasses=true';
3534+
utils.getVideoConfig(cypressConfig, bsConfig);
3535+
expect(outputConfig).to.be.eql(bsConfig.run_settings.config);
3536+
});
3537+
34663538
it('should return default hash and ignore video config in cypress config if enforce_settings is passed by the user', () => {
34673539
expect(utils.getVideoConfig({video: false}, {run_settings: {enforce_settings: true}})).to.be.eql({video: true, videoUploadOnPasses: true});
34683540
expect(utils.getVideoConfig({videoUploadOnPasses: false}, {run_settings: {enforce_settings: true}})).to.be.eql({video: true, videoUploadOnPasses: true});

0 commit comments

Comments
 (0)