Skip to content

Commit fa97586

Browse files
committed
Adding cypressProjectDir for overriding old cypress_proj_dir key
Moved logic of setting cypressProjectDir from either config_file_path or cypress_proj_dir Into the utls.js and chnaged relevant places where it is possibily used.
1 parent 71838b6 commit fa97586

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ const validate = (bsConfig, args) => {
110110

111111
if (!bsConfig.run_settings) reject(Constants.validationMessages.EMPTY_RUN_SETTINGS);
112112

113-
if (!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_CYPRESS_PROJ_DIR);
113+
if (!bsConfig.run_settings.cypress_proj_dir && !bsConfig.run_settings.userProvidedCypessConfigFile) {
114+
reject(Constants.validationMessages.EMPTY_CYPRESS_PROJ_DIR);
115+
}
114116

115117
// validate parallels specified in browserstack.json if parallels are not specified via arguments
116118
if (!Utils.isUndefined(args) && Utils.isUndefined(args.parallels) && !Utils.isParallelValid(bsConfig.run_settings.parallels)) reject(Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION);
@@ -119,10 +121,10 @@ const validate = (bsConfig, args) => {
119121
if (!Utils.isUndefined(args) && !Utils.isUndefined(args.parallels) && !Utils.isParallelValid(args.parallels)) reject(Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION);
120122

121123
// validate if config file provided exists or not when cypress_config_file provided
122-
// validate existing cypress_proj_dir key otherwise.
124+
// validate the cypressProjectDir key otherwise.
123125
let cypressConfigFilePath = bsConfig.run_settings.cypressConfigFilePath;
124126

125-
if (!fs.existsSync(cypressConfigFilePath) && bsConfig.run_settings.cypress_config_filename !== 'false') reject(Constants.validationMessages.CYPRESS_JSON_NOT_FOUND + cypressConfigFilePath);
127+
if (!fs.existsSync(cypressConfigFilePath) && bsConfig.run_settings.cypress_config_filename !== 'false') reject(Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE);
126128

127129
try {
128130
if (bsConfig.run_settings.cypress_config_filename !== 'false') {
@@ -133,7 +135,7 @@ const validate = (bsConfig, args) => {
133135
if (!Utils.isUndefined(cypressJson.baseUrl) && cypressJson.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET);
134136

135137
// Detect if the user is not using the right directory structure, and throw an error
136-
if (!Utils.isUndefined(cypressJson.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypress_proj_dir,cypressJson.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
138+
if (!Utils.isUndefined(cypressJson.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressJson.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
137139
}
138140
} catch(error){
139141
reject(Constants.validationMessages.INVALID_CYPRESS_JSON)

bin/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const validationMessages = {
2929
NOT_VALID_JSON: "browerstack.json is not a valid json",
3030
INVALID_EXTENSION: "Invalid files, please remove these files and try again.",
3131
INVALID_PARALLELS_CONFIGURATION: "Invalid value specified for parallels to use. Maximum parallels to use should be a number greater than 0.",
32+
INVALID_CYPRESS_CONFIG_FILE: "Invalid cypress_config_file",
3233
CYPRESS_JSON_NOT_FOUND: "cypress.json file is not found at cypress_proj_dir path ",
3334
INVALID_CYPRESS_JSON: "cypress.json is not a valid json",
3435
INVALID_DEFAULT_AUTH_PARAMS: "Your username and access key are required to run your tests on BrowserStack. Learn more at https://www.browserstack.com/docs/automate/cypress/authentication",

bin/helpers/usageReporting.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function local_cypress_version(bsConfig) {
3434
// 2. check version of Cypress installed globally if not present in project
3535

3636
if (bsConfig) {
37-
let version = get_version(path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', '.bin', 'cypress'));
37+
let version = get_version(path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', '.bin', 'cypress'));
3838
if (!version) {
3939
version = get_version('cypress');
4040
}
@@ -81,7 +81,7 @@ function cli_version_and_path(bsConfig) {
8181
// 2. check version of Cypress installed globally if not present in project
8282

8383
if (bsConfig) {
84-
let _path = path.join(bsConfig.run_settings.cypress_proj_dir, 'node_modules', 'browserstack-cypress');
84+
let _path = path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', 'browserstack-cypress');
8585
let version = get_version(_path);
8686
if (!version) {
8787
version = get_version('browserstack-cypress');
@@ -127,7 +127,7 @@ function ci_environment() {
127127
}
128128
// CircleCI
129129
if (env.CI === "true" && env.CIRCLECI === "true") {
130-
return "CircleCI";
130+
return "CircleCI";
131131
}
132132
// Travis CI
133133
if (env.CI === "true" && env.TRAVIS === "true") {

bin/helpers/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ exports.getErrorCodeFromMsg = (errMsg) => {
5555
case Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE:
5656
errorCode = "invalid_directory_structure";
5757
break;
58+
case Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE:
59+
errorCode = "invalid_cypress_config_file";
60+
break;
5861
}
5962
if (
6063
errMsg.includes("Please use --config-file <path to browserstack.json>.")
@@ -168,7 +171,13 @@ exports.setCypressConfigFilename = (bsConfig, args) => {
168171
bsConfig.run_settings.cypress_config_filename = path.basename(bsConfig.run_settings.cypress_config_file);
169172
}
170173

171-
bsConfig.run_settings.cypressConfigFilePath = bsConfig.run_settings.userProvidedCypessConfigFile ? bsConfig.run_settings.cypress_config_file : path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
174+
if (bsConfig.run_settings.userProvidedCypessConfigFile){
175+
bsConfig.run_settings.cypressConfigFilePath = bsConfig.run_settings.cypress_config_file;
176+
bsConfig.run_settings.cypressProjectDir = path.dirname(bsConfig.run_settings.cypress_config_file);
177+
} else {
178+
bsConfig.run_settings.cypressConfigFilePath = path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
179+
bsConfig.run_settings.cypressProjectDir = bsConfig.run_settings.cypress_proj_dir;
180+
}
172181
}
173182

174183
// specs can be passed from bstack configuration file

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ describe("capabilityHelper.js", () => {
783783
],
784784
run_settings: {
785785
cypress_proj_dir: "random path",
786-
cypressConfigFilePath: "random path"
786+
cypressConfigFilePath: "random path",
787+
cypressProjectDir: "random path"
787788
},
788789
};
789790
});
@@ -799,7 +800,7 @@ describe("capabilityHelper.js", () => {
799800
.catch((error) => {
800801
chai.assert.equal(
801802
error,
802-
Constants.validationMessages.CYPRESS_JSON_NOT_FOUND + "random path"
803+
Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE
803804
);
804805
fs.existsSync.restore();
805806
});
@@ -860,6 +861,7 @@ describe("capabilityHelper.js", () => {
860861
error,
861862
Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE
862863
);
864+
863865
fs.existsSync.restore();
864866
fs.readFileSync.restore();
865867
});

test/unit/bin/helpers/usageReporting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe("usageReporting", () => {
340340
expect(isUsageReportingEnabled()).to.be.undefined;
341341
});
342342
});
343-
343+
344344
describe("ci_environment", () => {
345345
afterEach(() => {
346346
delete process.env.JENKINS_URL;

test/unit/support/fixtures/testObjects.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const sampleBsConfig = {
44
access_key: "random-access-key",
55
},
66
run_settings: {
7-
cypress_proj_dir: "random path"
7+
cypress_proj_dir: "random path",
8+
cypressConfigFilePath: "random path",
9+
cypressProjectDir: "random path"
810
}
911
};
1012

0 commit comments

Comments
 (0)