Skip to content

Commit 1249dab

Browse files
Merge pull request #122 from browserstack/fix_local_testing_bug
Local mode and id validation
2 parents c7a3b65 + 15de10a commit 1249dab

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const caps = (bsConfig, zip) => {
6868
// Local Mode
6969
if (obj.local === true && bsConfig.connection_settings.local_mode) {
7070
obj.localMode = bsConfig.connection_settings.local_mode;
71+
if (bsConfig.connection_settings.user_defined_local_mode_warning) {
72+
logger.warn(Constants.userMessages.INVALID_LOCAL_MODE_WARNING);
73+
}
7174
logger.info(`Local testing set up in ${obj.localMode} mode.`);
7275
}
7376

@@ -160,7 +163,9 @@ const validate = (bsConfig, args) => {
160163

161164
// validate local args i.e --local-mode and --local-identifier
162165

163-
if( Utils.searchForOption('--local-identifier') && (Utils.isUndefined(args.localIdentifier) || (!Utils.isUndefined(args.localIdentifier) && !args.localIdentifier.trim()))) reject(Constants.validationMessages.INVALID_LOCAL_IDENTIFIER);
166+
if( Utils.searchForOption('--local-identifier') && (Utils.isUndefined(args.localIdentifier) || (!Utils.isUndefined(args.localIdentifier) && !args.localIdentifier.trim()))) reject(Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER);
167+
168+
if( Utils.getLocalFlag(bsConfig.connection_settings) && (Utils.isUndefined(bsConfig["connection_settings"]["local_identifier"]) || ( !Utils.isUndefined(bsConfig["connection_settings"]["local_identifier"]) && !bsConfig["connection_settings"]["local_identifier"].trim()))) reject(Constants.validationMessages.INVALID_LOCAL_IDENTIFIER);
164169

165170
if( Utils.searchForOption('--local-mode') && ( Utils.isUndefined(args.localMode) || (!Utils.isUndefined(args.localMode) && !["always-on","on-demand"].includes(args.localMode)))) reject(Constants.validationMessages.INVALID_LOCAL_MODE);
166171

bin/helpers/constants.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const userMessages = {
3939
CHECK_DASHBOARD_AT: "Please check the build status at: ",
4040
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>. Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
4141
LOCAL_START_FAILED: "Local Testing setup failed.",
42-
LOCAL_STOP_FAILED: "Local Binary stop failed."
42+
LOCAL_STOP_FAILED: "Local Binary stop failed.",
43+
INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
4344
};
4445

4546
const validationMessages = {
@@ -60,9 +61,10 @@ const validationMessages = {
6061
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",
6162
LOCAL_NOT_SET: "To test <baseUrlValue> on BrowserStack, you will have to set up Local testing. Read more here: https://www.browserstack.com/docs/automate/cypress/local-testing",
6263
INCORRECT_DIRECTORY_STRUCTURE: "No tests to run. Note that your Cypress tests should be in the same directory where the cypress.json exists.",
63-
INVALID_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier <String>.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
64+
INVALID_CLI_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier <String>.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
6465
INVALID_LOCAL_MODE: "When using --local-mode, a value needs to be supplied. \n--local-mode (\"always-on\" | \"on-demand\").\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
65-
INVALID_LOCAL_CONFIG_FILE: "When using --local-config-file, a value needs to be supplied. \n--local-config-file \"path to local-config-file.yaml\".\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
66+
INVALID_LOCAL_CONFIG_FILE: "When using --local-config-file, a value needs to be supplied. \n--local-config-file \"path to local-config-file.yaml\".\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
67+
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
6668
};
6769

6870
const cliMessages = {

bin/helpers/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ exports.getErrorCodeFromMsg = (errMsg) => {
6161
case Constants.validationMessages.INVALID_LOCAL_IDENTIFIER:
6262
errorCode = 'invalid_local_identifier';
6363
break;
64+
case Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER:
65+
errorCode = 'invalid_local_identifier';
66+
break;
6467
case Constants.validationMessages.INVALID_LOCAL_MODE:
6568
errorCode = 'invalid_local_mode';
6669
break;
@@ -383,9 +386,11 @@ exports.setLocalMode = (bsConfig, args) => {
383386

384387
if (!this.isUndefined(args.localMode) && args.localMode == 'always-on') {
385388
local_mode = 'always-on';
389+
} else if (!localModeUndefined && !["always-on", "on-demand"].includes(bsConfig['connection_settings']['local_mode'])) {
390+
bsConfig.connection_settings.user_defined_local_mode_warning = bsConfig['connection_settings']['local_mode'];
386391
} else if (
387392
!this.isUndefined(bsConfig['connection_settings']['local_mode']) &&
388-
bsConfig['connection_settings']['local_mode'].toLowerCase() ===
393+
String(bsConfig['connection_settings']['local_mode']).toLowerCase() ===
389394
'always-on'
390395
) {
391396
local_mode = 'always-on';
@@ -611,7 +616,7 @@ exports.isJSONInvalid = (err, args) => {
611616
return false
612617
}
613618

614-
if( err === Constants.validationMessages.INVALID_LOCAL_IDENTIFIER || err === Constants.validationMessages.INVALID_LOCAL_MODE ){
619+
if( err === Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER || err === Constants.validationMessages.INVALID_LOCAL_MODE ){
615620
return false
616621
}
617622

test/unit/bin/helpers/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ describe('utils', () => {
8181
constant.validationMessages.INVALID_LOCAL_IDENTIFIER
8282
)
8383
).to.eq('invalid_local_identifier');
84+
expect(
85+
utils.getErrorCodeFromMsg(
86+
constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER
87+
)
88+
).to.eq('invalid_local_identifier');
8489
expect(
8590
utils.getErrorCodeFromMsg(
8691
constant.validationMessages.INVALID_LOCAL_MODE
@@ -1604,7 +1609,7 @@ describe('utils', () => {
16041609
});
16051610

16061611
it('JSON is invalid if local identifier is invalid', () =>{
1607-
let error = constant.validationMessages.INVALID_LOCAL_IDENTIFIER;
1612+
let error = constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER;
16081613
expect(utils.isJSONInvalid(error,{})).to.eq(false);
16091614
});
16101615

0 commit comments

Comments
 (0)