Skip to content

Commit 857f577

Browse files
Merge branch 'pre_prod' into Cypress_cli_stats_instrumentation
2 parents 7955948 + 83e67cf commit 857f577

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

bin/commands/runs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
2+
const path = require('path');
3+
24
const archiver = require("../helpers/archiver"),
35
zipUploader = require("../helpers/zipUpload"),
46
build = require("../helpers/build"),
@@ -116,6 +118,9 @@ module.exports = function run(args) {
116118
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
117119
markBlockEnd('zip.archive');
118120

121+
let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName));
122+
let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName));
123+
119124
// Uploaded zip file
120125
markBlockStart('zip.zipUpload');
121126
return zipUploader.zipUpload(bsConfig, md5data, packageData).then(async function (zip) {
@@ -193,6 +198,8 @@ module.exports = function run(args) {
193198
package_error: utils.checkError(packageData),
194199
checkmd5_error: utils.checkError(md5data),
195200
build_id: data.build_id,
201+
test_zip_size: test_zip_size,
202+
npm_zip_size: npm_zip_size,
196203
};
197204
if (bsConfig && bsConfig.connection_settings) {
198205
if (bsConfig.connection_settings.local_mode) {

bin/helpers/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,13 @@ async function processExitHandler(exitData){
10251025
await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args);
10261026
process.exit(0);
10271027
}
1028+
1029+
exports.fetchZipSize = (fileName) => {
1030+
try {
1031+
let stats = fs.statSync(fileName)
1032+
return stats.size; // in bytes
1033+
}
1034+
catch(err) {
1035+
return 0;
1036+
}
1037+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browserstack-cypress-cli",
3-
"version": "1.10.1",
3+
"version": "1.11.0",
44
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
55
"main": "index.js",
66
"scripts": {

test/unit/bin/commands/runs.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ describe("runs", () => {
397397
setConfigStub = sandbox.stub();
398398
setBrowsersStub = sandbox.stub();
399399
setCLIModeStub = sandbox.stub();
400+
fetchZipSizeStub = sandbox.stub();
400401
});
401402

402403
afterEach(() => {
@@ -438,7 +439,8 @@ describe("runs", () => {
438439
setLocalConfigFile: setLocalConfigFileStub,
439440
setBrowsers: setBrowsersStub,
440441
setConfig: setConfigStub,
441-
setCLIMode: setCLIModeStub
442+
setCLIMode: setCLIModeStub,
443+
fetchZipSize: fetchZipSizeStub,
442444
},
443445
'../helpers/capabilityHelper': {
444446
validate: capabilityValidatorStub,
@@ -468,6 +470,7 @@ describe("runs", () => {
468470
packageInstallerStub.returns(Promise.resolve({ packageArchieveCreated: false }));
469471
archiverStub.returns(Promise.resolve("Zipping completed"));
470472
zipUploadStub.returns(Promise.reject("random-error"));
473+
fetchZipSizeStub.returns(123);
471474

472475
return runs(args)
473476
.then(function (_bsConfig) {
@@ -476,6 +479,7 @@ describe("runs", () => {
476479
.catch((error) => {
477480
sinon.assert.calledOnce(getConfigPathStub);
478481
sinon.assert.calledOnce(getConfigPathStub);
482+
sinon.assert.calledTwice(fetchZipSizeStub);
479483
sinon.assert.calledOnce(setLocalModeStub);
480484
sinon.assert.calledOnce(setLocalConfigFileStub);
481485
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
@@ -555,6 +559,7 @@ describe("runs", () => {
555559
setConfigStub = sandbox.stub();
556560
setBrowsersStub = sandbox.stub();
557561
setCLIModeStub = sandbox.stub();
562+
fetchZipSizeStub = sandbox.stub();
558563
});
559564

560565
afterEach(() => {
@@ -597,7 +602,8 @@ describe("runs", () => {
597602
setLocalConfigFile: setLocalConfigFileStub,
598603
setBrowsers: setBrowsersStub,
599604
setConfig: setConfigStub,
600-
setCLIMode: setCLIModeStub
605+
setCLIMode: setCLIModeStub,
606+
fetchZipSize: fetchZipSizeStub,
601607
},
602608
'../helpers/capabilityHelper': {
603609
validate: capabilityValidatorStub,
@@ -634,6 +640,7 @@ describe("runs", () => {
634640
zipUploadStub.returns(Promise.resolve("zip uploaded"));
635641
stopLocalBinaryStub.returns(Promise.resolve("nothing"));
636642
createBuildStub.returns(Promise.reject("random-error"));
643+
fetchZipSizeStub.returns(123);
637644

638645
return runs(args)
639646
.then(function (_bsConfig) {
@@ -642,6 +649,7 @@ describe("runs", () => {
642649
.catch((error) => {
643650
sinon.assert.calledOnce(getConfigPathStub);
644651
sinon.assert.calledOnce(getConfigPathStub);
652+
sinon.assert.calledTwice(fetchZipSizeStub);
645653
sinon.assert.calledOnce(setLocalConfigFileStub);
646654
sinon.assert.calledOnce(setLocalModeStub);
647655
sinon.assert.calledOnce(setupLocalTestingStub);
@@ -706,6 +714,9 @@ describe("runs", () => {
706714
return "end";
707715
});
708716
dashboardUrl = "dashboard-url";
717+
packageDirName = "package-dir";
718+
packageFileName = "package-file";
719+
fileName = "file-name";
709720
capabilityValidatorStub = sandbox.stub();
710721
archiverStub = sandbox.stub();
711722
zipUploadStub = sandbox.stub();
@@ -736,6 +747,7 @@ describe("runs", () => {
736747
nonEmptyArrayStub = sandbox.stub();
737748
setCLIModeStub = sandbox.stub();
738749
setProcessHooksStub = sandbox.stub();
750+
fetchZipSizeStub = sandbox.stub();
739751
});
740752

741753
afterEach(() => {
@@ -748,7 +760,7 @@ describe("runs", () => {
748760
let errorCode = null;
749761
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
750762
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`;
751-
let data = { user_id: 1234, parallels: 10, time_components: {}, unique_id: 'random_hash', package_error: 'test', checkmd5_error: 'test', build_id: 'random_build_id'}
763+
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}
752764

753765
const runs = proxyquire('../../../../bin/commands/runs', {
754766
'../helpers/utils': {
@@ -786,7 +798,8 @@ describe("runs", () => {
786798
nonEmptyArray: nonEmptyArrayStub,
787799
checkError: checkErrorStub,
788800
setCLIMode: setCLIModeStub,
789-
setProcessHooks: setProcessHooksStub
801+
setProcessHooks: setProcessHooksStub,
802+
fetchZipSize: fetchZipSizeStub,
790803
},
791804
'../helpers/capabilityHelper': {
792805
validate: capabilityValidatorStub,
@@ -806,6 +819,9 @@ describe("runs", () => {
806819
},
807820
'../helpers/config': {
808821
dashboardUrl: dashboardUrl,
822+
packageDirName: packageDirName,
823+
packageFileName: packageFileName,
824+
fileName: fileName,
809825
},
810826
'../helpers/checkUploaded': {
811827
checkUploadedMd5: checkUploadedStub,
@@ -836,6 +852,7 @@ describe("runs", () => {
836852
checkErrorStub.returns('test');
837853
getParallelsStub.returns(10);
838854
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl, user_id: 1234 }));
855+
fetchZipSizeStub.returns(123);
839856

840857
return runs(args)
841858
.then(function (_bsConfig) {
@@ -851,6 +868,7 @@ describe("runs", () => {
851868
sinon.assert.calledOnce(getParallelsStub);
852869
sinon.assert.calledOnce(setParallelsStub);
853870
sinon.assert.calledOnce(warnSpecLimitStub);
871+
sinon.assert.calledTwice(fetchZipSizeStub);
854872
sinon.assert.calledOnce(setLocalStub);
855873
sinon.assert.calledOnce(setLocalModeStub);
856874
sinon.assert.calledOnce(setupLocalTestingStub);

test/unit/bin/helpers/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,4 +2695,16 @@ describe('utils', () => {
26952695
process.exit.restore();
26962696
});
26972697
});
2698+
2699+
describe('fetchZipSize', () => {
2700+
it('should return size in bytes if file is present', () => {
2701+
sinon.stub(fs, 'statSync').returns({size: 123});
2702+
expect(utils.fetchZipSize('unknown.zip')).to.be.eql(123);
2703+
fs.statSync.restore();
2704+
});
2705+
2706+
it('handle file not present', () => {
2707+
expect(utils.fetchZipSize('unknown.tar.gz')).to.be.eql(0);
2708+
});
2709+
});
26982710
});

0 commit comments

Comments
 (0)