diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index a7855e03..0872f6b8 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -68,6 +68,9 @@ const caps = (bsConfig, zip) => { // Local Mode if (obj.local === true && bsConfig.connection_settings.local_mode) { obj.localMode = bsConfig.connection_settings.local_mode; + if (bsConfig.connection_settings.user_defined_local_mode_warning) { + logger.warn(Constants.userMessages.INVALID_LOCAL_MODE_WARNING); + } logger.info(`Local testing set up in ${obj.localMode} mode.`); } @@ -160,7 +163,9 @@ const validate = (bsConfig, args) => { // validate local args i.e --local-mode and --local-identifier - if( Utils.searchForOption('--local-identifier') && (Utils.isUndefined(args.localIdentifier) || (!Utils.isUndefined(args.localIdentifier) && !args.localIdentifier.trim()))) reject(Constants.validationMessages.INVALID_LOCAL_IDENTIFIER); + if( Utils.searchForOption('--local-identifier') && (Utils.isUndefined(args.localIdentifier) || (!Utils.isUndefined(args.localIdentifier) && !args.localIdentifier.trim()))) reject(Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER); + + 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); 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); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index ed9f13b9..e0a289c6 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -39,7 +39,8 @@ const userMessages = { CHECK_DASHBOARD_AT: "Please check the build status at: ", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", - LOCAL_STOP_FAILED: "Local Binary stop failed." + LOCAL_STOP_FAILED: "Local Binary stop failed.", + 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" }; const validationMessages = { @@ -60,9 +61,10 @@ const validationMessages = { 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", LOCAL_NOT_SET: "To test on BrowserStack, you will have to set up Local testing. Read more here: https://www.browserstack.com/docs/automate/cypress/local-testing", INCORRECT_DIRECTORY_STRUCTURE: "No tests to run. Note that your Cypress tests should be in the same directory where the cypress.json exists.", - INVALID_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier .\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference", + INVALID_CLI_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier .\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference", 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", - 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" + 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", + INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference" }; const cliMessages = { diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 3c70a00b..b27c8b16 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -61,6 +61,9 @@ exports.getErrorCodeFromMsg = (errMsg) => { case Constants.validationMessages.INVALID_LOCAL_IDENTIFIER: errorCode = 'invalid_local_identifier'; break; + case Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER: + errorCode = 'invalid_local_identifier'; + break; case Constants.validationMessages.INVALID_LOCAL_MODE: errorCode = 'invalid_local_mode'; break; @@ -383,9 +386,11 @@ exports.setLocalMode = (bsConfig, args) => { if (!this.isUndefined(args.localMode) && args.localMode == 'always-on') { local_mode = 'always-on'; + } else if (!localModeUndefined && !["always-on", "on-demand"].includes(bsConfig['connection_settings']['local_mode'])) { + bsConfig.connection_settings.user_defined_local_mode_warning = bsConfig['connection_settings']['local_mode']; } else if ( !this.isUndefined(bsConfig['connection_settings']['local_mode']) && - bsConfig['connection_settings']['local_mode'].toLowerCase() === + String(bsConfig['connection_settings']['local_mode']).toLowerCase() === 'always-on' ) { local_mode = 'always-on'; @@ -611,7 +616,7 @@ exports.isJSONInvalid = (err, args) => { return false } - if( err === Constants.validationMessages.INVALID_LOCAL_IDENTIFIER || err === Constants.validationMessages.INVALID_LOCAL_MODE ){ + if( err === Constants.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER || err === Constants.validationMessages.INVALID_LOCAL_MODE ){ return false } diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 505c2cc1..1cdd615a 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -81,6 +81,11 @@ describe('utils', () => { constant.validationMessages.INVALID_LOCAL_IDENTIFIER ) ).to.eq('invalid_local_identifier'); + expect( + utils.getErrorCodeFromMsg( + constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER + ) + ).to.eq('invalid_local_identifier'); expect( utils.getErrorCodeFromMsg( constant.validationMessages.INVALID_LOCAL_MODE @@ -1604,7 +1609,7 @@ describe('utils', () => { }); it('JSON is invalid if local identifier is invalid', () =>{ - let error = constant.validationMessages.INVALID_LOCAL_IDENTIFIER; + let error = constant.validationMessages.INVALID_CLI_LOCAL_IDENTIFIER; expect(utils.isJSONInvalid(error,{})).to.eq(false); });