Skip to content

Commit

Permalink
Merge pull request #205 from browserstack/video_instrumentation
Browse files Browse the repository at this point in the history
set video config in run settings as passed in cypress.json
  • Loading branch information
nagpalkaran95 committed Jan 14, 2022
2 parents 92fb9dd + 7ae4d07 commit f96ddb0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ module.exports = function run(args, rawArgs) {
//get the number of spec files
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);

bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressJson);

// return the number of parallels user specified
let userSpecifiedParallels = utils.getParallels(bsConfig, args);

Expand Down
11 changes: 11 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,3 +1053,14 @@ exports.fetchZipSize = (fileName) => {
return 0;
}
}

exports.getVideoConfig = (cypressJson) => {
let conf = {
video: true,
videoUploadOnPasses: true
}
if (!this.isUndefined(cypressJson.video)) conf.video = cypressJson.video;
if (!this.isUndefined(cypressJson.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressJson.videoUploadOnPasses;

return conf;
}
16 changes: 14 additions & 2 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ describe("runs", () => {
setBrowsersStub = sandbox.stub();
setConfigStub = sandbox.stub();
setCLIModeStub = sandbox.stub();
getVideoConfigStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -290,7 +291,8 @@ describe("runs", () => {
setSystemEnvs: setSystemEnvsStub,
setBrowsers: setBrowsersStub,
setConfig: setConfigStub,
setCLIMode: setCLIModeStub
setCLIMode: setCLIModeStub,
getVideoConfig: getVideoConfigStub,
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -339,6 +341,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setHeadedStub);
sinon.assert.calledOnce(setNoWrapStub);
sinon.assert.calledOnce(setCLIModeStub);
sinon.assert.calledOnce(getVideoConfigStub);
sinon.assert.calledOnce(setOtherConfigsStub);
sinon.assert.calledOnce(validateBstackJsonStub);
sinon.assert.calledOnce(capabilityValidatorStub);
Expand Down Expand Up @@ -405,6 +408,7 @@ describe("runs", () => {
setBrowsersStub = sandbox.stub();
setCLIModeStub = sandbox.stub();
fetchZipSizeStub = sandbox.stub();
getVideoConfigStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -448,6 +452,7 @@ describe("runs", () => {
setConfig: setConfigStub,
setCLIMode: setCLIModeStub,
fetchZipSize: fetchZipSizeStub,
getVideoConfig: getVideoConfigStub,
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -487,6 +492,7 @@ describe("runs", () => {
sinon.assert.calledOnce(getConfigPathStub);
sinon.assert.calledOnce(getConfigPathStub);
sinon.assert.calledTwice(fetchZipSizeStub);
sinon.assert.calledOnce(getVideoConfigStub);
sinon.assert.calledOnce(setLocalModeStub);
sinon.assert.calledOnce(setLocalConfigFileStub);
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
Expand Down Expand Up @@ -569,6 +575,7 @@ describe("runs", () => {
setBrowsersStub = sandbox.stub();
setCLIModeStub = sandbox.stub();
fetchZipSizeStub = sandbox.stub();
getVideoConfigStub = sandbox.stub();
});

afterEach(() => {
Expand Down Expand Up @@ -613,6 +620,7 @@ describe("runs", () => {
setConfig: setConfigStub,
setCLIMode: setCLIModeStub,
fetchZipSize: fetchZipSizeStub,
getVideoConfig: getVideoConfigStub,
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -659,6 +667,7 @@ describe("runs", () => {
sinon.assert.calledOnce(getConfigPathStub);
sinon.assert.calledOnce(getConfigPathStub);
sinon.assert.calledTwice(fetchZipSizeStub);
sinon.assert.calledOnce(getVideoConfigStub);
sinon.assert.calledOnce(setLocalConfigFileStub);
sinon.assert.calledOnce(setLocalModeStub);
sinon.assert.calledOnce(setupLocalTestingStub);
Expand Down Expand Up @@ -759,6 +768,7 @@ describe("runs", () => {
setCLIModeStub = sandbox.stub();
setProcessHooksStub = sandbox.stub();
fetchZipSizeStub = sandbox.stub();
getVideoConfigStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -771,7 +781,7 @@ describe("runs", () => {
let errorCode = null;
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`;
let data = { user_id: 1234, parallels: 10, time_components: {}, unique_id: 'random_hash', package_error: 'test', checkmd5_error: 'test', build_id: 'random_build_id', test_zip_size: 123, npm_zip_size: 123}
let data = { user_id: 1234, parallels: 10, time_components: {}, unique_id: 'random_hash', package_error: 'test', checkmd5_error: 'test', build_id: 'random_build_id', test_zip_size: 123, npm_zip_size: 123, test_suite_zip_upload: 1, package_zip_upload: 1}

const runs = proxyquire('../../../../bin/commands/runs', {
'../helpers/utils': {
Expand Down Expand Up @@ -811,6 +821,7 @@ describe("runs", () => {
setCLIMode: setCLIModeStub,
setProcessHooks: setProcessHooksStub,
fetchZipSize: fetchZipSizeStub,
getVideoConfig: getVideoConfigStub,
},
'../helpers/capabilityHelper': {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -880,6 +891,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setParallelsStub);
sinon.assert.calledOnce(warnSpecLimitStub);
sinon.assert.calledTwice(fetchZipSizeStub);
sinon.assert.calledOnce(getVideoConfigStub);
sinon.assert.calledOnce(setLocalStub);
sinon.assert.calledOnce(setLocalModeStub);
sinon.assert.calledOnce(setupLocalTestingStub);
Expand Down
13 changes: 13 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2763,4 +2763,17 @@ describe('utils', () => {
expect(utils.fetchZipSize('unknown.tar.gz')).to.be.eql(0);
});
});

describe('getVideoConfig', () => {
it('should return default hash if no config is passed by the user', () => {
expect(utils.getVideoConfig({})).to.be.eql({video: true, videoUploadOnPasses: true});
expect(utils.getVideoConfig({reporter: "mochawesome"})).to.be.eql({video: true, videoUploadOnPasses: true});
});

it('should replace video config as passed by the user', () => {
expect(utils.getVideoConfig({video: false})).to.be.eql({video: false, videoUploadOnPasses: true});
expect(utils.getVideoConfig({videoUploadOnPasses: false})).to.be.eql({video: true, videoUploadOnPasses: false});
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false})).to.be.eql({video: false, videoUploadOnPasses: false});
});
});
});

0 comments on commit f96ddb0

Please sign in to comment.