Skip to content

Commit 150df98

Browse files
Merge pull request #217 from browserstack/revert-188-CYP-810-add-support-for-home-directory
Revert "Add support for home directory in CLI"
2 parents e3a0d0c + 6bd0aad commit 150df98

File tree

7 files changed

+9
-203
lines changed

7 files changed

+9
-203
lines changed

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: 0 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>.")

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,6 @@ describe("capabilityHelper.js", () => {
554554
});
555555
});
556556

557-
describe("addCypressZipStartLocation", () => {
558-
it("returns correct zip start location", () => {
559-
let runSettings = {
560-
home_directory: "/some/path",
561-
cypressConfigFilePath: "/some/path/that/is/nested/file.json"
562-
};
563-
capabilityHelper.addCypressZipStartLocation(runSettings);
564-
chai.assert.equal(runSettings.cypressZipStartLocation, "that/is/nested");
565-
});
566-
});
567-
568557
describe("validate", () => {
569558

570559
describe("validate parallels specified in bsconfig and arguments", () => {
@@ -1064,115 +1053,5 @@ describe("capabilityHelper.js", () => {
10641053
})
10651054
});
10661055
});
1067-
1068-
describe("validate home directory", () => {
1069-
beforeEach(() => {
1070-
bsConfig = {
1071-
auth: {},
1072-
browsers: [
1073-
{
1074-
browser: "chrome",
1075-
os: "Windows 10",
1076-
versions: ["78", "77"],
1077-
},
1078-
],
1079-
run_settings: {
1080-
cypress_proj_dir: "random path",
1081-
cypressConfigFilePath: "random path",
1082-
cypressProjectDir: "random path"
1083-
},
1084-
};
1085-
});
1086-
1087-
it("does not exist", () => {
1088-
bsConfig.run_settings.cypressConfigFilePath = 'false';
1089-
bsConfig.run_settings.cypress_config_filename = 'false';
1090-
bsConfig.run_settings.home_directory = '/some/random';
1091-
1092-
sinon.stub(fs, 'existsSync').returns(false);
1093-
fs.existsSync.restore();
1094-
1095-
return capabilityHelper
1096-
.validate(bsConfig, {})
1097-
.then(function (data) {
1098-
chai.assert.fail("Promise error");
1099-
})
1100-
.catch((error) => {
1101-
chai.assert.equal(
1102-
error,
1103-
Constants.validationMessages.HOME_DIRECTORY_NOT_FOUND
1104-
);
1105-
});
1106-
});
1107-
1108-
it("is not a directory", () => {
1109-
bsConfig.run_settings.cypressConfigFilePath = 'false';
1110-
bsConfig.run_settings.cypress_config_filename = 'false';
1111-
bsConfig.run_settings.home_directory = '/some/random/file.ext';
1112-
1113-
sinon.stub(fs, 'existsSync').returns(true);
1114-
sinon.stub(fs, 'statSync').returns({ isDirectory: () => false });
1115-
1116-
return capabilityHelper
1117-
.validate(bsConfig, {})
1118-
.then(function (data) {
1119-
chai.assert.fail("Promise error");
1120-
})
1121-
.catch((error) => {
1122-
chai.assert.equal(
1123-
error,
1124-
Constants.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY
1125-
);
1126-
fs.existsSync.restore();
1127-
fs.statSync.restore();
1128-
});
1129-
});
1130-
1131-
it("does not contain cypressConfigFilePath", () => {
1132-
bsConfig.run_settings.cypressConfigFilePath = 'false';
1133-
bsConfig.run_settings.cypress_config_filename = 'false';
1134-
bsConfig.run_settings.home_directory = '/some/random';
1135-
1136-
sinon.stub(fs, 'existsSync').returns(true);
1137-
sinon.stub(fs, 'statSync').returns({ isDirectory: () => true });
1138-
1139-
return capabilityHelper
1140-
.validate(bsConfig, {})
1141-
.then(function (data) {
1142-
chai.assert.fail("Promise error");
1143-
})
1144-
.catch((error) => {
1145-
chai.assert.equal(
1146-
error,
1147-
Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY
1148-
);
1149-
fs.existsSync.restore();
1150-
fs.statSync.restore();
1151-
});
1152-
});
1153-
1154-
it("does not contain cypressConfigFilePath with special chars", () => {
1155-
bsConfig.run_settings.cypressConfigFilePath = 'false';
1156-
bsConfig.run_settings.cypress_config_filename = 'false';
1157-
bsConfig.run_settings.home_directory = '/$some!@#$%^&*()_+=-[]{};:<>?\'\\\//random';
1158-
1159-
sinon.stub(fs, 'existsSync').returns(true);
1160-
sinon.stub(fs, 'statSync').returns({ isDirectory: () => true });
1161-
1162-
return capabilityHelper
1163-
.validate(bsConfig, {})
1164-
.then(function (data) {
1165-
chai.assert.fail("Promise error");
1166-
})
1167-
.catch((error) => {
1168-
chai.assert.equal(
1169-
error,
1170-
Constants.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY
1171-
);
1172-
fs.existsSync.restore();
1173-
fs.statSync.restore();
1174-
});
1175-
});
1176-
});
11771056
});
11781057
});

test/unit/bin/helpers/utils.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,6 @@ describe('utils', () => {
105105
constant.validationMessages.INVALID_LOCAL_ASYNC_ARGS
106106
)
107107
).to.eq('invalid_local_async_args');
108-
expect(
109-
utils.getErrorCodeFromMsg(
110-
constant.validationMessages.HOME_DIRECTORY_NOT_FOUND
111-
)
112-
).to.eq('home_directory_not_found');
113-
expect(
114-
utils.getErrorCodeFromMsg(
115-
constant.validationMessages.HOME_DIRECTORY_NOT_A_DIRECTORY
116-
)
117-
).to.eq('home_directory_not_a_directory');
118-
expect(
119-
utils.getErrorCodeFromMsg(
120-
constant.validationMessages.CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY
121-
)
122-
).to.eq('cypress_config_file_not_part_of_home_directory');
123108
expect(
124109
utils.getErrorCodeFromMsg('Invalid browserstack.json file.')
125110
).to.eq('bstack_json_invalid');

0 commit comments

Comments
 (0)