Skip to content

Commit f96ddb0

Browse files
Merge pull request #205 from browserstack/video_instrumentation
set video config in run settings as passed in cypress.json
2 parents 92fb9dd + 7ae4d07 commit f96ddb0

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ module.exports = function run(args, rawArgs) {
9696
//get the number of spec files
9797
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
9898

99+
bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressJson);
100+
99101
// return the number of parallels user specified
100102
let userSpecifiedParallels = utils.getParallels(bsConfig, args);
101103

bin/helpers/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,3 +1053,14 @@ exports.fetchZipSize = (fileName) => {
10531053
return 0;
10541054
}
10551055
}
1056+
1057+
exports.getVideoConfig = (cypressJson) => {
1058+
let conf = {
1059+
video: true,
1060+
videoUploadOnPasses: true
1061+
}
1062+
if (!this.isUndefined(cypressJson.video)) conf.video = cypressJson.video;
1063+
if (!this.isUndefined(cypressJson.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressJson.videoUploadOnPasses;
1064+
1065+
return conf;
1066+
}

test/unit/bin/commands/runs.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ describe("runs", () => {
249249
setBrowsersStub = sandbox.stub();
250250
setConfigStub = sandbox.stub();
251251
setCLIModeStub = sandbox.stub();
252+
getVideoConfigStub = sandbox.stub();
252253
});
253254

254255
afterEach(() => {
@@ -290,7 +291,8 @@ describe("runs", () => {
290291
setSystemEnvs: setSystemEnvsStub,
291292
setBrowsers: setBrowsersStub,
292293
setConfig: setConfigStub,
293-
setCLIMode: setCLIModeStub
294+
setCLIMode: setCLIModeStub,
295+
getVideoConfig: getVideoConfigStub,
294296
},
295297
'../helpers/capabilityHelper': {
296298
validate: capabilityValidatorStub,
@@ -339,6 +341,7 @@ describe("runs", () => {
339341
sinon.assert.calledOnce(setHeadedStub);
340342
sinon.assert.calledOnce(setNoWrapStub);
341343
sinon.assert.calledOnce(setCLIModeStub);
344+
sinon.assert.calledOnce(getVideoConfigStub);
342345
sinon.assert.calledOnce(setOtherConfigsStub);
343346
sinon.assert.calledOnce(validateBstackJsonStub);
344347
sinon.assert.calledOnce(capabilityValidatorStub);
@@ -405,6 +408,7 @@ describe("runs", () => {
405408
setBrowsersStub = sandbox.stub();
406409
setCLIModeStub = sandbox.stub();
407410
fetchZipSizeStub = sandbox.stub();
411+
getVideoConfigStub = sandbox.stub();
408412
});
409413

410414
afterEach(() => {
@@ -448,6 +452,7 @@ describe("runs", () => {
448452
setConfig: setConfigStub,
449453
setCLIMode: setCLIModeStub,
450454
fetchZipSize: fetchZipSizeStub,
455+
getVideoConfig: getVideoConfigStub,
451456
},
452457
'../helpers/capabilityHelper': {
453458
validate: capabilityValidatorStub,
@@ -487,6 +492,7 @@ describe("runs", () => {
487492
sinon.assert.calledOnce(getConfigPathStub);
488493
sinon.assert.calledOnce(getConfigPathStub);
489494
sinon.assert.calledTwice(fetchZipSizeStub);
495+
sinon.assert.calledOnce(getVideoConfigStub);
490496
sinon.assert.calledOnce(setLocalModeStub);
491497
sinon.assert.calledOnce(setLocalConfigFileStub);
492498
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
@@ -569,6 +575,7 @@ describe("runs", () => {
569575
setBrowsersStub = sandbox.stub();
570576
setCLIModeStub = sandbox.stub();
571577
fetchZipSizeStub = sandbox.stub();
578+
getVideoConfigStub = sandbox.stub();
572579
});
573580

574581
afterEach(() => {
@@ -613,6 +620,7 @@ describe("runs", () => {
613620
setConfig: setConfigStub,
614621
setCLIMode: setCLIModeStub,
615622
fetchZipSize: fetchZipSizeStub,
623+
getVideoConfig: getVideoConfigStub,
616624
},
617625
'../helpers/capabilityHelper': {
618626
validate: capabilityValidatorStub,
@@ -659,6 +667,7 @@ describe("runs", () => {
659667
sinon.assert.calledOnce(getConfigPathStub);
660668
sinon.assert.calledOnce(getConfigPathStub);
661669
sinon.assert.calledTwice(fetchZipSizeStub);
670+
sinon.assert.calledOnce(getVideoConfigStub);
662671
sinon.assert.calledOnce(setLocalConfigFileStub);
663672
sinon.assert.calledOnce(setLocalModeStub);
664673
sinon.assert.calledOnce(setupLocalTestingStub);
@@ -759,6 +768,7 @@ describe("runs", () => {
759768
setCLIModeStub = sandbox.stub();
760769
setProcessHooksStub = sandbox.stub();
761770
fetchZipSizeStub = sandbox.stub();
771+
getVideoConfigStub = sandbox.stub();
762772
});
763773

764774
afterEach(() => {
@@ -771,7 +781,7 @@ describe("runs", () => {
771781
let errorCode = null;
772782
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
773783
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`;
774-
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}
784+
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}
775785

776786
const runs = proxyquire('../../../../bin/commands/runs', {
777787
'../helpers/utils': {
@@ -811,6 +821,7 @@ describe("runs", () => {
811821
setCLIMode: setCLIModeStub,
812822
setProcessHooks: setProcessHooksStub,
813823
fetchZipSize: fetchZipSizeStub,
824+
getVideoConfig: getVideoConfigStub,
814825
},
815826
'../helpers/capabilityHelper': {
816827
validate: capabilityValidatorStub,
@@ -880,6 +891,7 @@ describe("runs", () => {
880891
sinon.assert.calledOnce(setParallelsStub);
881892
sinon.assert.calledOnce(warnSpecLimitStub);
882893
sinon.assert.calledTwice(fetchZipSizeStub);
894+
sinon.assert.calledOnce(getVideoConfigStub);
883895
sinon.assert.calledOnce(setLocalStub);
884896
sinon.assert.calledOnce(setLocalModeStub);
885897
sinon.assert.calledOnce(setupLocalTestingStub);

test/unit/bin/helpers/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,4 +2763,17 @@ describe('utils', () => {
27632763
expect(utils.fetchZipSize('unknown.tar.gz')).to.be.eql(0);
27642764
});
27652765
});
2766+
2767+
describe('getVideoConfig', () => {
2768+
it('should return default hash if no config is passed by the user', () => {
2769+
expect(utils.getVideoConfig({})).to.be.eql({video: true, videoUploadOnPasses: true});
2770+
expect(utils.getVideoConfig({reporter: "mochawesome"})).to.be.eql({video: true, videoUploadOnPasses: true});
2771+
});
2772+
2773+
it('should replace video config as passed by the user', () => {
2774+
expect(utils.getVideoConfig({video: false})).to.be.eql({video: false, videoUploadOnPasses: true});
2775+
expect(utils.getVideoConfig({videoUploadOnPasses: false})).to.be.eql({video: true, videoUploadOnPasses: false});
2776+
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false})).to.be.eql({video: false, videoUploadOnPasses: false});
2777+
});
2778+
});
27662779
});

0 commit comments

Comments
 (0)