Skip to content

Commit 94575ba

Browse files
authored
Merge branch 'master' into CYP-912-IP-Geolocation
2 parents 3c7444e + 954028a commit 94575ba

File tree

10 files changed

+52
-210
lines changed

10 files changed

+52
-210
lines changed

bin/commands/runs.js

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

102+
bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressJson);
103+
102104
// return the number of parallels user specified
103105
let userSpecifiedParallels = utils.getParallels(bsConfig, args);
104106

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);
@@ -198,33 +189,11 @@ const validate = (bsConfig, args) => {
198189
} catch(error){
199190
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
200191
}
201-
202-
//check if home_directory is present or not in user run_settings
203-
if (!Utils.isUndefined(bsConfig.run_settings.home_directory)) {
204-
// check if home_directory exists or not
205-
if (!fs.existsSync(bsConfig.run_settings.home_directory)) {
206-
reject(Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND);
207-
}
208-
209-
// check if home_directory is a directory or not
210-
if (!fs.statSync(bsConfig.run_settings.home_directory).isDirectory()) {
211-
reject(Constants.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY);
212-
}
213-
214-
// check if cypress config file (cypress.json) is a part of home_directory or not
215-
if (!path.resolve(bsConfig.run_settings.cypressConfigFilePath).includes(path.resolve(bsConfig.run_settings.home_directory))) {
216-
reject(Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY);
217-
}
218-
219-
addCypressZipStartLocation(bsConfig.run_settings);
220-
}
221-
222192
resolve(cypressJson);
223193
});
224194
}
225195

226196
module.exports = {
227197
caps,
228-
addCypressZipStartLocation,
229198
validate
230199
}

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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ const validationMessages = {
9191
NOT_SUPPORTED_GEO_LOCATION: "The country code you have passed for IP Geolocation is currently not supported. Please refer the link https://www.browserstack.com/ip-geolocation for a list of supported countries.",
9292
NOT_AVAILABLE_GEO_LOCATION: "The country code you have passed for IP Geolocation is not available at the moment. Please try again in a few hours.",
9393
ACCESS_DENIED_GEO_LOCATION: "'geolocation' (IP Geolocation feature) capability is not supported in your account. It is only available under Enterprise plans, refer https://www.browserstack.com/ip-geolocation for more details.",
94-
NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE: "IP Geolocation feature is not available in conjunction with BrowserStack Local.",
95-
HOME_DIRECTORY_NOT_FOUND: "Specified home directory could not be found. Please make sure the path of the home directory is correct.",
96-
HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
97-
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."
94+
NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE: "IP Geolocation feature is not available in conjunction with BrowserStack Local."
9895
};
9996

10097
const cliMessages = {

bin/helpers/utils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@ exports.getErrorCodeFromMsg = (errMsg) => {
9191
case Constants.validationMessages.NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE:
9292
errorCode = 'not_allowed_geo_location_and_local_mode';
9393
break;
94-
case Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND:
95-
errorCode = 'home_directory_not_found';
96-
break;
97-
case Constants.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY:
98-
errorCode = 'home_directory_not_a_directory';
99-
break;
100-
case Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY:
101-
errorCode = 'cypress_config_file_not_part_of_home_directory';
102-
break;
10394
}
10495
if (
10596
errMsg.includes("Please use --config-file <path to browserstack.json>.")
@@ -1090,3 +1081,14 @@ exports.fetchZipSize = (fileName) => {
10901081
return 0;
10911082
}
10921083
}
1084+
1085+
exports.getVideoConfig = (cypressJson) => {
1086+
let conf = {
1087+
video: true,
1088+
videoUploadOnPasses: true
1089+
}
1090+
if (!this.isUndefined(cypressJson.video)) conf.video = cypressJson.video;
1091+
if (!this.isUndefined(cypressJson.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressJson.videoUploadOnPasses;
1092+
1093+
return conf;
1094+
}

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
@@ -253,6 +253,7 @@ describe("runs", () => {
253253
setConfigStub = sandbox.stub();
254254
setCLIModeStub = sandbox.stub();
255255
setGeolocationStub = sandbox.stub();
256+
getVideoConfigStub = sandbox.stub();
256257
});
257258

258259
afterEach(() => {
@@ -295,7 +296,8 @@ describe("runs", () => {
295296
setBrowsers: setBrowsersStub,
296297
setConfig: setConfigStub,
297298
setCLIMode: setCLIModeStub,
298-
setGeolocation: setGeolocationStub
299+
setGeolocation: setGeolocationStub,
300+
getVideoConfig: getVideoConfigStub,
299301
},
300302
'../helpers/capabilityHelper': {
301303
validate: capabilityValidatorStub,
@@ -344,6 +346,7 @@ describe("runs", () => {
344346
sinon.assert.calledOnce(setHeadedStub);
345347
sinon.assert.calledOnce(setNoWrapStub);
346348
sinon.assert.calledOnce(setCLIModeStub);
349+
sinon.assert.calledOnce(getVideoConfigStub);
347350
sinon.assert.calledOnce(setOtherConfigsStub);
348351
sinon.assert.calledOnce(validateBstackJsonStub);
349352
sinon.assert.calledOnce(capabilityValidatorStub);
@@ -412,6 +415,7 @@ describe("runs", () => {
412415
setCLIModeStub = sandbox.stub();
413416
fetchZipSizeStub = sandbox.stub();
414417
setGeolocationStub = sandbox.stub();
418+
getVideoConfigStub = sandbox.stub();
415419
});
416420

417421
afterEach(() => {
@@ -456,6 +460,7 @@ describe("runs", () => {
456460
setCLIMode: setCLIModeStub,
457461
fetchZipSize: fetchZipSizeStub,
458462
setGeolocation: setGeolocationStub,
463+
getVideoConfig: getVideoConfigStub,
459464
},
460465
'../helpers/capabilityHelper': {
461466
validate: capabilityValidatorStub,
@@ -495,6 +500,7 @@ describe("runs", () => {
495500
sinon.assert.calledOnce(getConfigPathStub);
496501
sinon.assert.calledOnce(getConfigPathStub);
497502
sinon.assert.calledTwice(fetchZipSizeStub);
503+
sinon.assert.calledOnce(getVideoConfigStub);
498504
sinon.assert.calledOnce(setLocalModeStub);
499505
sinon.assert.calledOnce(setLocalConfigFileStub);
500506
sinon.assert.calledOnce(getNumberOfSpecFilesStub);
@@ -579,6 +585,7 @@ describe("runs", () => {
579585
setCLIModeStub = sandbox.stub();
580586
fetchZipSizeStub = sandbox.stub();
581587
setGeolocationStub = sandbox.stub();
588+
getVideoConfigStub = sandbox.stub();
582589
});
583590

584591
afterEach(() => {
@@ -624,6 +631,7 @@ describe("runs", () => {
624631
setCLIMode: setCLIModeStub,
625632
fetchZipSize: fetchZipSizeStub,
626633
setGeolocation: setGeolocationStub,
634+
getVideoConfig: getVideoConfigStub,
627635
},
628636
'../helpers/capabilityHelper': {
629637
validate: capabilityValidatorStub,
@@ -670,6 +678,7 @@ describe("runs", () => {
670678
sinon.assert.calledOnce(getConfigPathStub);
671679
sinon.assert.calledOnce(getConfigPathStub);
672680
sinon.assert.calledTwice(fetchZipSizeStub);
681+
sinon.assert.calledOnce(getVideoConfigStub);
673682
sinon.assert.calledOnce(setLocalConfigFileStub);
674683
sinon.assert.calledOnce(setLocalModeStub);
675684
sinon.assert.calledOnce(setupLocalTestingStub);
@@ -772,6 +781,7 @@ describe("runs", () => {
772781
setProcessHooksStub = sandbox.stub();
773782
fetchZipSizeStub = sandbox.stub();
774783
setGeolocationStub = sandbox.stub();
784+
getVideoConfigStub = sandbox.stub();
775785
});
776786

777787
afterEach(() => {
@@ -784,7 +794,7 @@ describe("runs", () => {
784794
let errorCode = null;
785795
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
786796
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}`;
787-
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}
797+
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}
788798

789799
const runs = proxyquire('../../../../bin/commands/runs', {
790800
'../helpers/utils': {
@@ -825,6 +835,7 @@ describe("runs", () => {
825835
setProcessHooks: setProcessHooksStub,
826836
fetchZipSize: fetchZipSizeStub,
827837
setGeolocation: setGeolocationStub,
838+
getVideoConfig: getVideoConfigStub,
828839
},
829840
'../helpers/capabilityHelper': {
830841
validate: capabilityValidatorStub,
@@ -894,6 +905,7 @@ describe("runs", () => {
894905
sinon.assert.calledOnce(setParallelsStub);
895906
sinon.assert.calledOnce(warnSpecLimitStub);
896907
sinon.assert.calledTwice(fetchZipSizeStub);
908+
sinon.assert.calledOnce(getVideoConfigStub);
897909
sinon.assert.calledOnce(setLocalStub);
898910
sinon.assert.calledOnce(setLocalModeStub);
899911
sinon.assert.calledOnce(setupLocalTestingStub);

0 commit comments

Comments
 (0)