Skip to content

Commit b1aff81

Browse files
committed
Merge branch 'master' of github.com:roshan04/browserstack-cypress-cli
2 parents 0fff8be + 954028a commit b1aff81

File tree

10 files changed

+51
-207
lines changed

10 files changed

+51
-207
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/archiver.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
2-
const fs = require("fs"),
3-
path = require("path");
2+
const fs = require("fs");
43

54
const archiver = require("archiver"),
65
Constants = require('../helpers/constants'),
76
logger = require("./logger").winstonLogger,
8-
utils = require('../helpers/utils');
7+
utils = require('../helpers/utils'),
8+
path = require('path');
99

1010
const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
1111
return new Promise(function (resolve, reject) {
@@ -14,17 +14,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
1414
}
1515
var output = fs.createWriteStream(filePath);
1616

17-
var cypressFolderPath = '';
18-
let cypressAppendFilesZipLocation = '';
19-
if (runSettings.home_directory) {
20-
cypressFolderPath = runSettings.home_directory;
21-
cypressAppendFilesZipLocation = runSettings.cypressZipStartLocation;
22-
if (cypressAppendFilesZipLocation !== '') {
23-
cypressAppendFilesZipLocation += '/';
24-
}
25-
} else {
26-
cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
27-
}
17+
var cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
2818

2919
logger.info(`Creating tests.zip with files in ${cypressFolderPath}`);
3020

@@ -71,7 +61,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
7161

7262
if (Object.keys(packageJSON).length > 0) {
7363
let packageJSONString = JSON.stringify(packageJSON, null, 4);
74-
archive.append(packageJSONString, {name: `${cypressAppendFilesZipLocation}browserstack-package.json`});
64+
archive.append(packageJSONString, {name: 'browserstack-package.json'});
7565
}
7666

7767
// do not add cypress.json if arg provided is false
@@ -83,7 +73,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
8373
fs.readFileSync(runSettings.cypressConfigFilePath)
8474
);
8575
let cypressJSONString = JSON.stringify(cypressJSON, null, 4);
86-
archive.append(cypressJSONString, {name: `${cypressAppendFilesZipLocation}cypress.json`});
76+
archive.append(cypressJSONString, {name: 'cypress.json'});
8777
}
8878

8979
archive.finalize();

bin/helpers/capabilityHelper.js

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
const fs = require('fs'),
2-
path = require('path');
3-
41
const logger = require("./logger").winstonLogger,
52
Constants = require("./constants"),
6-
Utils = require("./utils");
3+
Utils = require("./utils"),
4+
fs = require('fs');
75

86
const caps = (bsConfig, zip) => {
97
return new Promise(function (resolve, reject) {
@@ -131,13 +129,6 @@ const caps = (bsConfig, zip) => {
131129
})
132130
}
133131

134-
const addCypressZipStartLocation = (runSettings) => {
135-
let resolvedHomeDirectoryPath = path.resolve(runSettings.home_directory);
136-
let resolvedCypressConfigFilePath = path.resolve(runSettings.cypressConfigFilePath);
137-
runSettings.cypressZipStartLocation = path.dirname(resolvedCypressConfigFilePath.split(resolvedHomeDirectoryPath)[1]);
138-
runSettings.cypressZipStartLocation = runSettings.cypressZipStartLocation.substring(1);
139-
}
140-
141132
const validate = (bsConfig, args) => {
142133
return new Promise(function (resolve, reject) {
143134
logger.info(Constants.userMessages.VALIDATING_CONFIG);
@@ -194,33 +185,11 @@ const validate = (bsConfig, args) => {
194185
} catch(error){
195186
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
196187
}
197-
198-
//check if home_directory is present or not in user run_settings
199-
if (!Utils.isUndefined(bsConfig.run_settings.home_directory)) {
200-
// check if home_directory exists or not
201-
if (!fs.existsSync(bsConfig.run_settings.home_directory)) {
202-
reject(Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND);
203-
}
204-
205-
// check if home_directory is a directory or not
206-
if (!fs.statSync(bsConfig.run_settings.home_directory).isDirectory()) {
207-
reject(Constants.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY);
208-
}
209-
210-
// check if cypress config file (cypress.json) is a part of home_directory or not
211-
if (!path.resolve(bsConfig.run_settings.cypressConfigFilePath).includes(path.resolve(bsConfig.run_settings.home_directory))) {
212-
reject(Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY);
213-
}
214-
215-
addCypressZipStartLocation(bsConfig.run_settings);
216-
}
217-
218188
resolve(cypressJson);
219189
});
220190
}
221191

222192
module.exports = {
223193
caps,
224-
addCypressZipStartLocation,
225194
validate
226195
}

bin/helpers/checkUploaded.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
1515
if (args["force-upload"]) {
1616
return resolve("force-upload");
1717
}
18-
let cypressFolderPath = undefined;
19-
if (runSettings.home_directory) {
20-
cypressFolderPath = runSettings.home_directory;
21-
} else {
22-
cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
23-
}
18+
let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
2419
let ignoreFiles = utils.getFilesToIgnore(runSettings, args.exclude, false);
2520
let options = {
2621
cwd: cypressFolderPath,

bin/helpers/constants.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ const validationMessages = {
8787
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
8888
INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference",
8989
INVALID_LOCAL_ASYNC_ARGS: "Cannot run in --async mode when local is set to true. Please run the build after removing --async",
90-
HOME_DIRECTORY_NOT_FOUND: "Specified home directory could not be found. Please make sure the path of the home directory is correct.",
91-
HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
92-
CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory."
9390
};
9491

9592
const cliMessages = {

bin/helpers/utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,6 @@ exports.getErrorCodeFromMsg = (errMsg) => {
8585
case Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS:
8686
errorCode = 'invalid_local_async_args';
8787
break;
88-
case Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND:
89-
errorCode = 'home_directory_not_found';
90-
break;
91-
case Constants.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY:
92-
errorCode = 'home_directory_not_a_directory';
93-
break;
94-
case Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY:
95-
errorCode = 'cypress_config_file_not_part_of_home_directory';
96-
break;
9788
}
9889
if (
9990
errMsg.includes("Please use --config-file <path to browserstack.json>.")
@@ -1062,3 +1053,14 @@ exports.fetchZipSize = (fileName) => {
10621053
return 0;
10631054
}
10641055
}
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+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browserstack-cypress-cli",
3-
"version": "1.11.1",
3+
"version": "1.11.2",
44
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
55
"main": "index.js",
66
"scripts": {
@@ -27,7 +27,7 @@
2727
"unzipper": "^0.10.11",
2828
"update-notifier": "^5.1.0",
2929
"uuid": "^8.3.2",
30-
"winston": "^2.3.1",
30+
"winston": "2.4.4",
3131
"yargs": "^14.2.3"
3232
},
3333
"repository": {

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);

0 commit comments

Comments
 (0)